MailBee.NET Objects退回邮件教程(一):SMTP部分

C#// Create SMTP objectSmtp 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 anyelse 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 servermailer.Disconnect();
VB.NET' Create SMTP objectDim 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 = Truemailer.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 IfEnd If' Disconnect from the servermailer.Disconnect()

试用、下载、了解更多产品信息请点击“咨询在线客服”   

MailBee.NET Objects退回邮件教程(一):SMTP部分

标签:电子邮件

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2017年7月19日
下一篇 2017年7月19日

相关推荐

发表回复

登录后才能评论