Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  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.

    mailman.i = CkMailMan::ckCreate()
    If mailman.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Configure the SMTP server connection.
    CkMailMan::setCkSmtpHost(mailman, "smtp.example.com")
    CkMailMan::setCkSmtpPort(mailman, 465)
    CkMailMan::setCkSmtpSsl(mailman, 1)
    CkMailMan::setCkSmtpUsername(mailman, "user@example.com")
    CkMailMan::setCkSmtpPassword(mailman, "myPassword")

    ;  Open the connection.

    success = CkMailMan::ckOpenSmtpConnection(mailman)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        ProcedureReturn
    EndIf

    ;  Reset the current SMTP mail transaction.
    success = CkMailMan::ckSmtpReset(mailman)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        ProcedureReturn
    EndIf

    success = CkMailMan::ckCloseSmtpConnection(mailman)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        ProcedureReturn
    EndIf

    Debug "Sent SMTP RSET."


    CkMailMan::ckDispose(mailman)


    ProcedureReturn
EndProcedure