问题描述
我有一个网络表单,有人可以在其中建立一个帐户-我想向他们发送一封电子邮件确认信.
I have a webform where someone can set up an account - I want to send them an email confirmation.
我正在使用的代码:
// 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);
web.config:
web.config:
<system.net>
<mailSettings>
<smtp>
<network host="[email protected]" port="9999" userName="[email protected]" password="OurOrganisationEmailPassword"/>
</smtp>
</mailSettings>
</system.net>
但是得到:
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]>
好像想要我要发送到的网址的用户登录详细信息.我该如何修改并发送确认电子邮件,就像其他所有商业公司一样?
Looks like it's wanting the user login details for the web address I'm wanting to send to. How can I amend this and send such confirmation emails like how all the other commercial companies do?
推荐答案
确定-正常运行了.下面是工作代码;看起来像我配置NetworkCredential对象是问题.谢谢大家的帮助,以帮助我达成解决方案.
OK - got it working. Below is the working coding; looks like me configuring the NetworkCredential object was the issue. Thanks everyone though for your assistance in helping me reach the solution.
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);
web.config
web.config
<system.net>
<mailSettings>
<smtp>
<network host="mail.ourdomain.com" port="9999" userName="[email protected]" password="OurOrganisationEmailPassword"/>
</smtp>
</mailSettings>
</system.net>
这篇关于如何从背后的C#代码发送电子邮件-获取System.Net.Mail.SmtpFailedRecipientException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!