我有一个网络表单,有人可以在其中设置帐户 - 我想向他们发送一封电子邮件确认。
我正在使用的代码:
// Create e-mail message
MailMessage mm = new MailMessage();
mm.From = new MailAddress("[email protected]", "Our Organisation");
mm.To.Add(new MailAddress("[email protected]", "Web User"));
mm.Subject = "Confirmation";
mm.Body = "You are now registered test";
mm.IsBodyHtml = true;
// Send e-mail
sc = new SmtpClient();
NetworkCredential basicAuthenticationInfo = new NetworkCredential(“[email protected]”, “ourorganisationemailPassword”);
sc.Credentials = basicAuthenticationInfo;
sc.UseDefaultCredentials = false;
sc.Send(mm);
网络配置:
<system.net>
<mailSettings>
<smtp>
<network host="[email protected]" port="9999" userName="[email protected]" password="OurOrganisationEmailPassword"/>
</smtp>
</mailSettings>
</system.net>
But get:
System.Net.Mail.SmtpFailedRecipientException was caught
HResult=-2146233088
Message=Mailbox unavailable. The server response was: Authentication is required for relay
Source=System
FailedRecipient=<[email protected]>
看起来它需要我想要发送到的网址的用户登录详细信息。我该如何修改这一点并像所有其他商业公司那样发送此类确认电子邮件?
好的 - 开始工作了。以下是工作编码;看起来我配置 NetworkCredential 对象是问题所在。感谢大家帮助我找到解决方案。
MailAddress fromAddress = new MailAddress("[email protected]","Our Organisation");//"[email protected]";
MailAddress toAddress = new MailAddress("[email protected]", "Web User"); //"[email protected]";
//Create the MailMessage instance
MailMessage myMailMessage = new MailMessage(fromAddress, toAddress);
//Assign the MailMessage's properties
myMailMessage.Subject = "Confirmation";
myMailMessage.Body = "You are now registered test";
myMailMessage.IsBodyHtml = true;
//Create the SmtpClient object
SmtpClient smtp = new SmtpClient();
//Send the MailMessage (will use the Web.config settings)
smtp.Send(myMailMessage);
网络配置
<system.net>
<mailSettings>
<smtp>
<network host="mail.ourdomain.com" port="9999" userName="[email protected]" password="OurOrganisationEmailPassword"/>
</smtp>
</mailSettings>
</system.net>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)