繁体   English   中英

没有默认凭据,ASP.Net C#应用程序不会发送电子邮件

[英]ASP.Net C# Application does not send e-mails without default credentials

大家好,我在ASP.Net项目中遇到一个问题,就像...曾经折磨我! 因此,我的问题是,在新用户注册后,我可以发送电子邮件,但是即使我将其设置为false,它也会使用默认凭据。 我不希望新用户看到我的实际gmail或Outlook电子邮件,而是希望将其带入更专业的水平,例如“ no-reply@imaginarydomain.com”或类似的东西。 我不会注册某些Web服务,而要花很多钱只是为了创建一个自动回复的电子邮件,我永远都不会检查您是否知道...这是我的Web.config SMTP代码:

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network" from="no-reply@mydomain.com">
    <network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="My actual Gmail" password="My Password" enableSsl="true" />
  </smtp>
</mailSettings>

这是我在Registration.aspx.cs中的代码:

MailMessage activationMail = new MailMessage();
            string useractivation = "http://localhost:53631/Account/Activation.aspx?username=" + username.Text;
            activationMail.From = new MailAddress("no-reply@mydomain.com", "My E-Mail Displaying Name");
            activationMail.To.Add(mail1.Text);
            StreamReader sRead = new StreamReader(Server.MapPath("~/Mails/ActivationMail.html"));
            string readFile = sRead.ReadToEnd();
            string Strcontent = "";
            Strcontent = readFile;
            Strcontent = Strcontent.Replace("[Name]", realname.Text);
            Strcontent = Strcontent.Replace("[Username]", username.Text);
            Strcontent = Strcontent.Replace("[Password]", pass1.Text);
            Strcontent = Strcontent.Replace("[useractivation]", useractivation);
            Strcontent = Strcontent.Replace("[Site]", "http://localhost:53631");
            Strcontent = Strcontent.Replace("[Facebook]", "facebook");
            activationMail.Subject = "Your Registration to ASP.Net website or something...";
            activationMail.Body = Strcontent.ToString();
            activationMail.IsBodyHtml = true;
            activationMail.BodyEncoding = UTF8Encoding.UTF8;
            activationMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            SmtpClient client = new SmtpClient();
            client.Send(activationMail);

如果有人有什么请在下面发表评论谢谢...

“ no-reply@mydomain.com”必须是有效的电子邮件。 Gmail不允许您使用不属于您或未链接到您帐户的别名。 检查此链接。

这是一个非常明显的安全问题,提供商无法允许发送来自无效/未验证电子邮件的电子邮件。

如果您拥有该域,我建议您使用Mandrill之类的工具来实现此功能。 您将免费获得12,000个免费配额。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM