Java
Java
Send an SMTP RSET Command
See more SMTP Examples
Demonstrates the Chilkat MailMan.SmtpReset method, which sends an SMTP RSET command to the server. RSET resets the server-side state of the current mail transaction. This example opens a connection, sends RSET, and closes.
Background: During an SMTP session a message is built up across
MAIL FROM and RCPT TO commands. If you need to abandon that partially-specified transaction — say an error occurred midway — RSET clears it without dropping the connection, so the same authenticated session can start a fresh message. It's a lightweight way to recover in-session rather than reconnecting.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Demonstrates the MailMan.SmtpReset method, which sends an SMTP RSET command to the server.
// RSET resets the server-side state of the current mail transaction.
CkMailMan mailman = new CkMailMan();
// Configure the SMTP server connection.
mailman.put_SmtpHost("smtp.example.com");
mailman.put_SmtpPort(465);
mailman.put_SmtpSsl(true);
mailman.put_SmtpUsername("user@example.com");
mailman.put_SmtpPassword("myPassword");
// Open the connection.
success = mailman.OpenSmtpConnection();
if (success == false) {
System.out.println(mailman.lastErrorText());
return;
}
// Reset the current SMTP mail transaction.
success = mailman.SmtpReset();
if (success == false) {
System.out.println(mailman.lastErrorText());
return;
}
success = mailman.CloseSmtpConnection();
if (success == false) {
System.out.println(mailman.lastErrorText());
return;
}
System.out.println("Sent SMTP RSET.");
}
}