C# // Create SMTP object Smtp mailer = new Smtp(); // Set the message fields. mailer.From.AsString = "jdoe@domain.com"; mailer.To.AsString = "bill@domain2.com"; mailer.Subject = "Hi"; mailer.BodyPlainText = "This is test message"; // Starts logging SMTP activities into a file. mailer.Log.Enabled = true; mailer.Log.Filename = @"C:\log.txt"; mailer.Log.Clear(); // Specify the server to use. If your server does not require authentication, // just omit both last parameters. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret"); // Attempt to connect. mailer.Connect(); // Display the host name of the server the connection was established with. Console.WriteLine("Connected to " + mailer.SmtpServers[mailer.GetCurrentSmtpServerIndex()].Name); // Make sure all the recipients are ok. if (mailer.TestSend(SendFailureThreshold.AllRecipientsFailed) != TestSendResult.OK) { Console.WriteLine("No recipients can receive the message."); }// Show refused recipients if any else if (mailer.GetRefusedRecipients().Count > 0) { Console.WriteLine("The following recipients failed: " + mailer.GetRefusedRecipients().ToString()); } else { Console.WriteLine("All recipients are ok. Will send the message now."); // Send e-mail. If it cannot be delivered, bounce will // arrive to bounce@domain3.com, not to joe@domain1.com mailer.Send("bounce@domain.com", (string)null); Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString()); } // Disconnect from the server mailer.Disconnect();
VB.NET ' Create SMTP object Dim mailer As New Smtp ' Set the message fields. mailer.From.AsString = "jdoe@domain.com" mailer.To.AsString = "bill@domain2.com" mailer.Subject = "Hi" mailer.BodyPlainText = "This is test message" ' Starts logging SMTP activities into a file. mailer.Log.Enabled = True mailer.Log.Filename = "C:\log.txt" mailer.Log.Clear() ' Specify the server to use. If your server does not require authentication, ' just remove last 2 parameters. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret") ' Attempt to connect. mailer.Connect() ' Display the host name of the server the connection was established with. Console.WriteLine("Connected to " + mailer.SmtpServers(mailer.GetCurrentSmtpServerIndex()).Name) ' Make sure all the recipients are ok. If mailer.TestSend(SendFailureThreshold.AllRecipientsFailed) <> TestSendResult.OK Then Console.WriteLine("No recipients can receive the message.") Else ' Show refused recipients if any If mailer.GetRefusedRecipients().Count > 0 Then Console.WriteLine("The following recipients failed: " & mailer.GetRefusedRecipients().ToString()) Else Console.WriteLine("All recipients are ok. Will send the message now.") ' Send e-mail. If it cannot be delivered, bounce will ' arrive to bounce@domain3.com, not to joe@domain1.com mailer.Send("bounce@domain.com", CType(Nothing, String)) Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString()) End If End If ' Disconnect from the server mailer.Disconnect()
C# Smtp mailer = new Smtp(); mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always; VB.NET Dim mailer As New Smtp() mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always
C# mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header; VB.NET mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header
C# mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d"; VB.NET mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d"
C# if (mailer.GetExtension("DSN") != null) { Console.WriteLine("The message will be submitted with DSN support"); } else { Console.WriteLine("The message will be submitted without DSN support"); } VB.NET If mailer.GetExtension("DSN") IsNot Nothing Then Console.WriteLine("The message will be submitted with DSN support") Else Console.WriteLine("The message will be submitted without DSN support") End If
C# // Create new MailMessage object. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Temp\MyMail.eml"); msg.ConfirmReceipt = "jdoe@domain.com"; VB.NET ' Create new MailMessage object. Dim msg As New MailMessage() msg.LoadMessage("C:\Temp\MyMail.eml") msg.ConfirmReceipt = "jdoe@domain.com"
C# // Create new MailMessage object. MailMessage msg = new MailMessage(); // Load the message from .eml file msg.LoadMessage(@"C:\Temp\MyMail.eml"); // Show the e-mail address of recipient of the read confirmation message. Console.WriteLine("Send confirmation to " + msg.ConfirmRead); VB.NET ' Create new MailMessage object. Dim msg As New MailMessage() ' Load the message from .eml file msg.LoadMessage("C:\Temp\MyMail.eml") ' Show the e-mail address of recipient of the read confirmation message. Console.WriteLine("Send confirmation to " + msg.ConfirmRead)
C# msg.LoadBodyText("http://www.google.com", MessageBodyType.Html, Encoding.Default, ImportBodyOptions.ImportRelatedFiles |ImportBodyOptions.ImportRelatedFilesFromUris | ImportBodyOptions.PathIsUri); VB.NET msg.LoadBodyText("http://www.google.com", MessageBodyType.Html, Encoding.Default, ImportBodyOptions.ImportRelatedFiles |ImportBodyOptions.ImportRelatedFilesFromUris | ImportBodyOptions.PathIsUri)
C# // Create a MailMessage object. MailMessage msg = new MailMessage(); // Add a header. msg.Headers.Add("MyHeader", "Some value for my own header", false); VB.NET ' Create a MailMessage object. Dim msg As New MailMessage() ' Add a header. msg.Headers.Add("MyHeader", "Some value for my own header", False)
C# // Remove the non-standard headers from the message. msg.Headers.RemoveCustomHeaders(); VB.NET ' Remove the non-standard headers from the message. msg.Headers.RemoveCustomHeaders()
C# // Remove the specified header. msg.Headers.Remove("X-Special-Header"); // Remove the first header. msg.Headers.RemoveAt(0); VB.NET ' Remove the specified header. msg.Headers.Remove("X-Special-Header") ' Remove the first header. msg.Headers.RemoveAt(0)