Dart.Mail Namespace > Smtp Class > Send Method : Send(MailMessage) Method |
Public Overloads Function Send( _ ByVal message As MailMessage _ ) As SmtpResult
Dim instance As Smtp Dim message As MailMessage Dim value As SmtpResult value = instance.Send(message)
public SmtpResult Send( MailMessage message )
public: SmtpResult* Send( MailMessage* message )
public: SmtpResult^ Send( MailMessage^ message )
Exception | Description |
---|---|
ProtocolException | Bad SMTP protocol response received from server. |
System.Net.Sockets.SocketException | A socket failure. |
System.InvalidOperationException | MailMessage.BitEncoding is TransferEncoding.EightBit or TransferEncoding.Binary and the server does not advertise 8bit or binary transport. |
System.FormatException | Bad address format. |
This method is used to send most email messages. Initialize a MailMessage as follows:
Alternatively, use Send(String,String,String,String) to send a basic text message, Send(MailMessage,String,String) to specify the mail addresses for the message envelope, or Send(Stream,String,String) to send a previously encoded message (stream).
This method automatically calls Connect and Authenticate if not connected to the server and SendDirectToMx is false.
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