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.
Here's my smtp settings:
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:
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.
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.
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. Here is a reference that might help.
I met more than 2 people when I wanted to send.
I'm just sending it to 2 people. My problem is solved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.