2011-11-04 63 views
1

發送電子郵件我設置服務器名smtp.mail.yahoo.com和端口是465我試圖發送電子郵件,但無法發送電子郵件未能在Gmail雅虎服務器發送電子郵件正在

什麼是正確的servername和smtp端口使用yahoo發送電子郵件

我需要設置哪些其他配置?

我的代碼是在這裏:

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

請定義「無法發送電子郵件」,發生了什麼?它是否會拋出異常,如果是的話,錯誤信息是什麼? –

+0

異常錯誤發送郵件失敗 – Ashwin

回答

6

我剛試過的代碼,我認爲雅虎郵件服務器沒有使用SSL,因爲如果你註釋掉

//smtp.Port = 465; 
//smtp.EnableSsl = true; 

它的工作原理。

+1

感謝我的朋友我已經完成 – Ashwin

+0

它正在爲我工​​作: EnableSsl = true; Port = 587; – Rahatur

1

我不確認你的smtp服務器設置這些工作正常對我來說。 取代你的smtp服務器設置,並從這段代碼片段有想法。

一些SMTP服務器非標準設置在這裏:

http://www.emailaddressmanager.com/tips/mail-settings.html

//使用雅虎ID 保護無效Button2_Click發送郵件(對象發件人,EventArgs的){ 字符串 = frmyahoo「fromid @ yahoo.com「; //替換你的雅虎郵箱ID String frmpwd =「fromidpwd」; //替換你的雅虎郵件pwd 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"; 
     } 
    } 
相關問題