PowerTCP Mail for .NET
Close Method (Smtp)
Example 




Cease all activity and gracefully close the control connection.
Syntax
Public Sub Close() 
Dim instance As Smtp
 
instance.Close()
public void Close()
public: void Close(); 
public:
void Close(); 
Exceptions
ExceptionDescription
ProtocolExceptionBad SMTP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.
Remarks

The Send methods automatically log into the SMTP server specified by Session.RemoteEndPoint. Use Close when the connection is no longer needed.

A "QUIT" command is sent to the server and waits until the server has closed the connection.

Use this method to terminate the connection. It differs from the Smtp.Dispose method in that the Smtp.Dispose method is used to abruptly close the connection and release all resources associated with the Smtp component.

Example
Uses the Smtp component to send a text message with an attachment.
private void sendMail(object sender)
{
    //Create message to send
    MailMessage message = new MailMessage();
    message.To = toAddress;
    message.From = fromAddress;
    message.Subject = "File Attached";
    message.Text = "Please see the attached file.";

    //Add the attachment
    message.Attachments.Add(new Attachment(Application.StartupPath + "\\myImage.jpg"));

    //Set session parameters
    smtp1.Session.RemoteEndPoint = 
        new Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session));
    smtp1.Session.Username = myUsername;
    smtp1.Session.Password = myPassword;

    //Send message
    smtp1.Send(message);

    //Logout gracefully
    smtp1.Close();
}

private void smtp1_Progress(object sender, SmtpProgressEventArgs e)
{
    //Update progress bar as message is sent
    progressBar1.Value = (e.Final) ? 0 : (int)((e.Position * 100) / e.Length);
}
Private Sub sendMail(ByVal sender As Object)
    'Create message to send
    Dim message As New MailMessage()
    message.To = toAddress
    message.From = fromAddress
    message.Subject = "File Attached"
    message.Text = "Please see the attached file."

    'Add the attachment
    message.Attachments.Add(New Attachment(Application.StartupPath & "\myImage.jpg"))

    'Set session parameters
    smtp1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session))
    smtp1.Session.Username = myUsername
    smtp1.Session.Password = myPassword

    'Send message
    smtp1.Send(message)

    'Logout gracefully
    smtp1.Close()
End Sub

Private Sub smtp1_Progress(ByVal sender As Object, ByVal e As SmtpProgressEventArgs) Handles smtp1.Progress
    'Update progress bar as message is sent
    progressBar1.Value = If(e.Final, 0, CInt((e.Position * 100) \ e.Length))
End Sub
See Also

Reference

Smtp Class
Smtp Members


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic