asp.net中的邮件发送错误 [英] Mail Sending Error in asp.net
问题描述
大家好!
我试图通过asp.net发送邮件,但它给了我错误.我用谷歌搜索,但是找到了与网络相关的答案,我不知道该怎么办.请帮我.
它给了我以下错误---
SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证.
这是我的.aspx.cs的代码
Hi all!!
i am trying to send mail through asp.net but it gives me error. i googled it but found answers related to networking and i had no idea what to do. Plz help me out.
it gives me the following error---
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Here is the code of my .aspx.cs
protected void btnSubmitt_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.Subject = "Enquiry From the User Of the WebSite";
mail.Body = "Dear sir , <br/> Following user has provided a feedback about your website <br/><br/>" + "<b>Name :</b>" + txtName.Text + "<br/><b>Email Id :</b>" + txtEmailId.Text + "<br/><b>Mobile No :</b>" + txtMobileNo.Text + "<br/><b>Feedback:</b>" + txtEnquiry.Text;
mail.From = new System.Net.Mail.MailAddress("arcwebsolutions@gmail.com", "Feedback From Website");
mail.IsBodyHtml = true;
mail.To.Add("ujjwal.uniyal111@gmail.com");
NetworkCredential cred = new NetworkCredential("arcwebsolutions@gmail.com", "password");
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.Send(mail);
clear();
}
推荐答案
尝试使用以下代码,希望它可以工作.根据您的要求更改credentials
(UserName
&Password
)和receiver
地址.
Try using the following code, hope it will work. Changecredentials
(UserName
&Password
) andreceiver
address according to yours.
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
// setup Smtp authentication
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("gmailusername@gmail.com", "gmailpassword");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("gmailusername@gmail.com");
msg.To.Add(new MailAddress("xyz@gmail.com"));
msg.Subject = "This is a test Email subject";
msg.IsBodyHtml = true;
msg.Body = string.Format("<html><head></head><body>Test HTML Email</body>");
try
{
client.Send(msg);
//lblMsg.Text = "Your message has been successfully sent.";
}
catch (Exception ex)
{
//lblMsg.ForeColor = Color.Red;
//lblMsg.Text = "Error occured while sending your message." + ex.Message;
}
确保已从 web.config 文件中删除了所有邮件设置.
让我知道是否有问题.
Make sure you have removed all mail settings from your web.config file.
Let me know if there is any issue.
在这里看看
http://stackoverflow.com/questions/704636/sending- email-through-gmail-smtp-server-with-c-sharp [
Have a look here
http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp[^]
The answer regarding password strength may well be your issue.
I suggest you change you password ASAP, since you''ve just posted it on a public forum!!
这篇关于asp.net中的邮件发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!