尝试从 ASP.NET 页面通过 SMTP 发送电子邮件时出现权限问题
我以前这样做过,没有任何问题,但现在我不知道出了什么问题。我有一个带有电子邮件按钮的网页,我想使用该按钮将一些数据发送到电子邮件地址。
我向我们的网络托管公司询问服务器详细信息,得到的答复是:
"You can use the following details for mail.
Incoming mail server: mail.ourSite.com Outgoing mail server: mail.ourSite.com
Username and password are the email address and password associated with the email address.
"
我不确定最后一行,但我在网络主机的控制面板中创建了一个新的电子邮件地址。
我使用的代码是:
// instantiate a new mail definition and load an html
// template into a string which I replace values in
// then the rest of the code below
md.Subject = String.Format("{0} {1} {2}", emailSubject, firstName, lastName);
MailMessage msg = md.CreateMailMessage(emailAddress, replacements, emailBody, new Control());
md.IsBodyHtml = true;
SmtpClient sc = new SmtpClient(emailServer);
sc.Credentials = new NetworkCredential(emailUsername, emailPassword);
try
{
sc.Send(msg);
}
emailServer - mail.ourSite.com(本文中的虚拟值) emailUsername - 我在控制面板中创建的电子邮件地址 emailPassword - 上面电子邮件的密码
我遇到的错误是,当我将电子邮件发送到我们自己的域之外的其他域时,我会收到
"Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server."
当我向我们主机内的地址发送电子邮件时,它工作正常。
支持不是很支持,所以我在这里问您认为问题可能是什么?我觉得很奇怪,我使用了自己创建的电子邮件地址的密码,真的应该这样吗?
I have done this before without any issue but now I don't know what's wrong. I have a web page with a button for email which I want to send some data to email addresses with.
I asked our web hosting company for server details and the response I got was:
"You can use the following details for mail.
Incoming mail server: mail.ourSite.com Outgoing mail server: mail.ourSite.com
Username and password are the email address and password associated with the email address.
"
I am not sure about the last line but I created a new email address in the web host's control panel.
The code I use is:
// instantiate a new mail definition and load an html
// template into a string which I replace values in
// then the rest of the code below
md.Subject = String.Format("{0} {1} {2}", emailSubject, firstName, lastName);
MailMessage msg = md.CreateMailMessage(emailAddress, replacements, emailBody, new Control());
md.IsBodyHtml = true;
SmtpClient sc = new SmtpClient(emailServer);
sc.Credentials = new NetworkCredential(emailUsername, emailPassword);
try
{
sc.Send(msg);
}
emailServer - mail.ourSite.com (dummy value in this post)
emailUsername - the email address I created in the control panel
emailPassword - the password for the email above
The error I have is that when I send emails to other domains than our own I get
"Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server."
When I email to an address within our host then it works fine.
The support is not very supportive so I am asking here what you might think the problem could be? I find it strange that I use the password for an email address I created, should it really be like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您为
NetworkCredential
使用了错误的电子邮件地址。它应该是您从提供emailServer
的电子邮件帐户获得的帐户。I think that you are using the wrong email address for the
NetworkCredential
. It should be the one for your email account that you got from the one providingemailServer
.试试这个..
Try this ..
这是发送邮件的代码..
我希望我对你有帮助..
here is code to send mail..
i hope i will helpful to you..