PowerTCP Mail for .NET
Progress Event (Smtp)
Example 




Raised repeatedly while an email message is sent.
Syntax
Event Data

The event handler receives an argument of type SmtpProgressEventArgs containing data related to this event. The following SmtpProgressEventArgs properties provide information specific to this event.

PropertyDescription
Final Returns true the last time a Progress event is raised for a given message. (Inherited from Dart.Mail.ProgressEventArgs)
Length The length of the message data. (Inherited from Dart.Mail.ProgressEventArgs)
MessageMailMessage being sent. Returns null if Send(Stream,String,String) was used.  
Position The position within the message data. (Inherited from Dart.Mail.ProgressEventArgs)
Remarks

SmtpProgressEventArgs is provided, containing data about the progress (such as byte position, length, etc). To display progress using a ProgressBar, use 0 for System.Windows.Forms.ProgressBar.Minimum, Length for System.Windows.Forms.ProgressBar.Maximum, and Position for System.Windows.Forms.ProgressBar.Value. For more information on using events within the Visual Studio.NET environment, see "Using Events Within The Visual Studio.NET Environment".

MailSession.BlockSize controls the granularity.

If you are using the Smtp component as a reference, you must create a method and wire up the event yourself. See "Using Events When A Component Is Used As A Reference".

Set ComponentBase.SynchronizingObject to enable marshaling of this event to the UI thread.

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