我一直在努力解决这个问题。我有两个按钮。一个按钮是从 Gmail发送邮件到Gmail ,另一个按钮用于 Gmail到Hotmail 。
我可以从我的Gmail 帐户发送邮件到另一个Gmail帐户,但从我的Gmail帐户发送到Hotmail时出现问题。
..邮箱不可用服务器.....服务器响应5.7.3请求 行动中止;用户未经过身份验证
五天后我即将放弃。 我已经检查了SO上的相关主题
请不要将其标记为副本。
private void gmailTogmail(object sender, EventArgs e)
{
var mail = new MailMessage();
var c = new MailAddressCollection { txtto.Text.Trim() };
mail.From = new MailAddress(txtfrom.Text.ToLower().Trim());
// mail.To.Add((c[0].Address));
mail.To.Add(txtto.Text.ToLower());
mail.Subject = "for hilk";
mail.Body = "some heeeeeee";
mail.IsBodyHtml = true;
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
Credentials = new NetworkCredential(txtfrom.Text.Trim(), txtpass.Text.Trim()),
EnableSsl = true
};
smtp.Send(mail);
MessageBox.Show("ok");
}
private void gmailToHotmail(object sender, EventArgs e)
{
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("mymail@gmail.com");
mail.To.Add("mailSento@hotmail.com");
mail.Subject = "Your Sub";
mail.IsBodyHtml = true;
//string htmlBody;
//htmlBody = "HTML code";
//mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.Timeout = 5000;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "Pass");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("ok");
}