发送电子邮件我设置服务器名称smtp.mail.yahoo.com和端口是465我试图发送电子邮件但无法发送电子邮件
使用yahoo发送电子邮件的正确servername和smtp端口是什么
我需要设置哪些其他配置?
我的代码在这里:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(address);
message.Subject = subject;
message.From = new System.Net.Mail.MailAddress(from);
message.Body = body;
message.Bcc.Add(bcc);
message.CC.Add(cc);
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mail.yahoo.com");
smtp.Credentials = new System.Net.NetworkCredential(emailid,password);
smtp.Port = 465;
smtp.EnableSsl = true;
smtp.Send(message);
答案 0 :(得分:6)
我刚刚尝试了代码,我认为雅虎邮件服务器不使用SSL,因为如果你注释掉
//smtp.Port = 465;
//smtp.EnableSsl = true;
它有效。
答案 1 :(得分:1)
我不确认您的smtp服务器设置这些对我来说运行正常.. 替换你的smtp服务器设置,并从这段代码片段中获取想法。
一些smtp服务器标准设置在这里:
http://www.emailaddressmanager.com/tips/mail-settings.html
//使用Yahoo id发送邮件 protected void Button2_Click(object sender,EventArgs e) { String frmyahoo =“fromid@yahoo.com”; //替换您的雅虎邮箱ID String frmpwd =“fromidpwd”; //替换你的雅虎邮件密码 String toId = txtTo.Text; String ccId = txtCc.Text; String bccId = txtBcc.Text; String msgsubject = txtSubject.Text; String mailContent = txtContent.Text;
try
{
MailMessage msg = new MailMessage();
msg.To.Add(toId);
MailAddress frmAdd = new MailAddress(frmyahoo);
msg.From = frmAdd;
//Check user enter CC address or not
if (ccId != "")
{
msg.CC.Add(ccId);
}
//Check user enter BCC address or not
if (bccId != "")
{
msg.Bcc.Add(bccId);
}
msg.Subject = msgsubject;
//Check for attachment is there
if (FileUpload1.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
msg.IsBodyHtml = true;
msg.Body = mailContent;
SmtpClient mailClient = new SmtpClient("smtp.mail.yahoo.com", 25);
NetworkCredential NetCrd = new NetworkCredential(frmyahoo, frmpwd);
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = false;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Send(msg);
clear();
Label1.Text = "Mail Sent Successfully";
}
catch (Exception ex)
{
Label1.Text = "Unable to send Mail Please try again later";
}
}