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);
that says:
我在smtp.Send(邮件)中出错;说:
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
. I am sending it to an @gmail.com
account though, so it is sending to a non-local e-mail address.
我环顾四周,如果他们在设置中使用不同的电子邮件发送电子邮件,其他人也有这个问题,但是我从info@mysite.com发送我的邮件。我将它发送到@gmail.com帐户,所以它将发送到一个非本地的电子邮件地址。
What am I doing wrong here?
我在这里做错了什么?
1 个解决方案
#1
1
I wanted to add the answer to this for others searching
我想为其他人的搜索添加答案。
Make sure SMTP is up and running and no errors are being thrown. Here is a reference that might help.
确保SMTP已启动并运行,并没有抛出错误。这里有一个可能会有所帮助的参考。
http://forums.iis.net/p/1157046/1901343.aspx
http://forums.iis.net/p/1157046/1901343.aspx
#1
1
I wanted to add the answer to this for others searching
我想为其他人的搜索添加答案。
Make sure SMTP is up and running and no errors are being thrown. Here is a reference that might help.
确保SMTP已启动并运行,并没有抛出错误。这里有一个可能会有所帮助的参考。
http://forums.iis.net/p/1157046/1901343.aspx
http://forums.iis.net/p/1157046/1901343.aspx