[英]How can I send emails from my SMTP server?
Hello I have a hosted Windows Server 2008 R2 Enterprise and a purchased domain name. 您好我有一个托管的Windows Server 2008 R2 Enterprise和一个购买的域名。 I have pointed everything on my domain to my server's dns and uploaded my ASP.Net site to the IIS. 我已经将我的域上的所有内容指向我的服务器的dns,并将我的ASP.Net站点上传到IIS。 I have also set up an SMTP Feature so now I'm trying to send emails from my SMTP but I can't because the application says that the user is not authenticated. 我还设置了一个SMTP功能,所以现在我正在尝试从我的SMTP发送电子邮件,但我不能,因为应用程序说用户未经过身份验证。 Here is the source code of my page: 这是我的页面的源代码:
MailMessage activationMail = new MailMessage();
activationMail.From = new MailAddress("no-reply@mydomain.com", "MyGame");
activationMail.To.Add(RegistrationEmail.Text);
StreamReader sRead = new StreamReader(Server.MapPath("~/Mails/ActivationMail.html"));
string readFile = sRead.ReadToEnd();
string Strcontent = "";
Strcontent = readFile;
Strcontent = Strcontent.Replace("[Name]", RegistrationRealName.Text);
Strcontent = Strcontent.Replace("[Username]", RegistrationUsername.Text);
Strcontent = Strcontent.Replace("[Password]", RegistrationPasswordCreate.Text);
Strcontent = Strcontent.Replace("[useractivation]", useractivation);
Strcontent = Strcontent.Replace("[Site]", site);
Strcontent = Strcontent.Replace("[Facebook]", "facebook");
activationMail.Subject = "My Game - Registration";
activationMail.Body = Strcontent.ToString();
sRead.Close();
activationMail.IsBodyHtml = true;
activationMail.BodyEncoding = UTF8Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Host = "mydomain";
NetworkCredential cr = new NetworkCredential();
cr.UserName = "User from AD DS";
cr.Password = "Password of User";
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Timeout = 10000;
client.Send(activationMail);
Note: My domain name is not the same with my forest's domain. 注意:我的域名与我的林域名不同。 I have also tried to set my forest's domain as the client.Host but same result. 我也尝试将我的林域设置为client.Host但结果相同。 I have these settings on my Web.config 我在我的Web.config上有这些设置
<mailSettings>
<smtp from="no-reply@mydomain">
<network defaultCredentials="false" host="localhost" />
</smtp>
</mailSettings>
My SMTP server's settings are these: 我的SMTP服务器的设置如下:
Does anybody know what am I doing wrong? 有人知道我做错了什么吗?
Add the following code as you haven't provided any credentials to the smtp: 添加以下代码,因为您没有向smtp提供任何凭据:
client.Credentials = cr;
Like: 喜欢:
NetworkCredential cr = new NetworkCredential();
cr.UserName = "User from AD DS";
cr.Password = "Password of User";
client.Credentials = cr;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Timeout = 10000;
client.Send(activationMail);
try adding these two line: 尝试添加这两行:
client.EnableSsl = false;
client.Credentials = cr;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.