[英]Permission error when sending e-mail using my SMTP server in IIS7
I just recently bought my own server with IIS7, and I'm trying to set up SMTP so that I can send an e-mail from my website. 我最近刚用IIS7购买了自己的服务器,并且正在尝试设置SMTP,以便可以从我的网站发送电子邮件。
Here's my smtp settings: 这是我的smtp设置:
Here is my code that sends the e-mail: 这是我发送电子邮件的代码:
private static void SendEmail(IEnumerable<MailAddress> to,
IEnumerable<MailAddress> bcc, MailAddress from,
string subject, string bodyHtml)
{
var mail = new MailMessage { From = from, Subject = subject,
Body = bodyHtml, IsBodyHtml = true };
foreach (var address in to)
{
mail.To.Add(address);
}
foreach (var address in bcc)
{
mail.Bcc.Add(address);
}
try
{
string server = ConfigurationManager.AppSettings["SMTPServer"];
int port = Int32.Parse(ConfigurationManager.AppSettings["SMTPPort"]);
var smtp = new SmtpClient
{
Host = server,
Port = port
};
smtp.Send(mail);
}
catch (Exception err)
{
}
}
And my config settings: 而我的配置设置:
<add key="SMTPServer" value="localhost" />
<add key="SMTPPort" value="25" />
I get an error at smtp.Send(mail);
我在smtp.Send(mail);
遇到错误smtp.Send(mail);
that says: 说的是:
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. 请检查您的邮件客户端设置,或与管理员联系以验证是否为此服务器定义了域或地址。
Well, I have no authentication requirements on my smtp server, it says so in my settings in the screenshot. 好吧,我的smtp服务器上没有身份验证要求,它在屏幕快照中的设置中是这样说的。
I looked around, and other people had this problem if they were sending the e-mail from a different e-mail specified in their settings, but I'm sending mine from info@mysite.com
. 我环顾四周,如果其他人从设置中指定的其他电子邮件中发送电子邮件,则出现了此问题,但是我从info@mysite.com
发送我的info@mysite.com
。 I am sending it to an @gmail.com
account though, so it is sending to a non-local e-mail address. 我将其发送到@gmail.com
帐户,因此它正在发送到非本地电子邮件地址。
What am I doing wrong here? 我在这里做错了什么?
I wanted to add the answer to this for others searching 我想为其他搜索添加答案
Make sure SMTP is up and running and no errors are being thrown. 确保SMTP已启动并正在运行,并且没有引发任何错误。 Here is a reference that might help. 这是一个可能有用的参考。
http://forums.iis.net/p/1157046/1901343.aspx http://forums.iis.net/p/1157046/1901343.aspx
I met more than 2 people when I wanted to send. 我想发送时遇到了2个以上的人。
I'm just sending it to 2 people. 我只是发送给2个人。 My problem is solved. 我的问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.