如何解决电子邮件发送中的错误 [英] how to solve the error in email sending
本文介绍了如何解决电子邮件发送中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我出现错误
SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.7.0必须首先发出STARTTLS命令. kr4sm12198444pbc.76
durin发送电子邮件
.cs
i hv a error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. kr4sm12198444pbc.76
durin sending email
.cs
NetworkCredential nt = new NetworkCredential("*************@gmail.com", "12345678");
string usermail = ds.Tables[0].Rows[0][0].ToString();
string passwd = ds.Tables[0].Rows[0][1].ToString();
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Credentials = nt;
mail.From = new MailAddress(Text2.Value);
mail.To.Add(new MailAddress(usermail));
mail.IsBodyHtml = true;
mail.Subject = "Password";
mail.Body = "Your password is : " + passwd + "";
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Send(mail);//here is error
lbl.Visible = true;
lbl.Text = "password sent successfully";
mail.To.Clear();
mail.Dispose();
我该怎么办....
what should i do....
推荐答案
private void MailSendThruGmail()
{
MailAddress fromAddress = new MailAddress("sender@gmail.com", "From Name");
MailAddress toAddress = new MailAddress("recipient@gmail.com", "To Name");
const string subject = "test";
const string body = @"Using this feature, you can send an e-mail message from an application very easily.";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body);
msg.IsBodyHtml = true;
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("username", "password"),
EnableSsl = true
};
try
{
client.Send(msg);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
请不要使用Gmail进行测试.使用免费的本地电子邮件服务器,例如HmailServer.
Please do not use Gmail for testing. Use your own local email server, like HmailServer, which is free.
MailMessage message = new MailMessage();
message.From = new MailAddress("Ngqandu.Anele@gmail.com");
message.To.Add(new MailAddress("Anele.Ngqandu@live.nmmu.ac.za"));
message.Subject = subject.Text;
message.Body = body.Text;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("Ngqandu.Anele@gmail.com", "password");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(message);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
这篇关于如何解决电子邮件发送中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文