发送邮件时出错 [英] Error getting while sending mail

查看:74
本文介绍了发送邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的网站发送邮件时出现以下错误.在本地iis中它可以工作,但是在生产服务器中却出现以下错误.

Sys.WebForms.PageRequestManagerServerErrorException:SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证.

我写的代码是

I am getting following error while sending a mail from my website. In local iis it is working but in production server it is getting following error.

Sys.WebForms.PageRequestManagerServerErrorException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

The code i have written is

public void SendMail(string ToEmailAddress, string Body, string Subject)
        {
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"].ToString();
            smtpClient.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientport"].ToString());
            smtpClient.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["MailPassword"].ToString());
            smtpClient.EnableSsl = true;
            MailMessage messege = new MailMessage();
            MailAddress mailAddress = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Name"].ToString());
            messege.From = mailAddress;
            messege.To.Add(ToEmailAddress);
            messege.Subject = Subject;
            messege.Body = Body;
            messege.IsBodyHtml = true;
            smtpClient.Send(messege);
        }      



在web.config中,我提到了类似
的设置



In web.config i have mention settings like

<appSettings>
       <add key="SmtpClientHost" value="smtp.gmail.com"/>
       <add key="SmtpClientport" value="587"/>
       <add key="FromEmail" value="crackersstore@gmail.com"/>
       <add key="MailPassword" value="myPassword"/>
       <add key="Name" value="CRACKERSADMIN"/>
   </appSettings>


请帮助我


Please help me

推荐答案

尝试如下配置,确保已在Web.Config中配置SMTP配置:
Try configuration like following, make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>


如果需要,请查看此Microsoft Video教程:在以下位置发送电子邮件带有或不带有附件的C#:通用例程. [


If needed, have a look at this Microsoft Video tutorial: Use ASP.NET to send Email from Website[^]


Have a look at this tip too: Sending an Email in C# with or without attachments: generic routine.[^]


这篇关于发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆