San*_*r M 15 c# system.net.mail
下面是我的编码,只是看看它
System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage();
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
oMail.From = new System.Net.Mail.MailAddress("one@gmail.com");
oMail.To.Add(TextBox1.Text.Trim());
oMail.Subject = "Subject*";
oMail.Body = "Body*";
oMail.IsBodyHtml = true;
smtp.Host = "smtp.sendgrid.net";
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("myusername", "mypassword");
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(oMail);
Run Code Online (Sandbox Code Playgroud)
在这里,我需要检查邮件是否已经发送.
And*_*lov 20
你不能.由于您使用SMTP,一般情况下,无法判断传递是否成功.阅读SMTP规范.邮件在发送时被路由,因此:
smtp.Send()
.您可以设置to 的DeliveryNotificationOptions
属性.MailMessage
OnSuccess
这里有更多信息:http://msdn.microsoft.com/en-us/library/system.net.mail.deliverynotificationoptions.aspx
在这里:http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.deliverynotificationoptions.aspx
正如评论中指出的那样,这种方法并非100%可靠.这只是一个选择.
归档时间: |
|
查看次数: |
44159 次 |
最近记录: |