2012-06-29 75 views
1

我想從雅虎發送電子郵件到雅虎bt未能發送它。我使用收到的網絡。請查看我的代碼憑證。沒有例外或錯誤,但是當郵箱打開時,沒有電子郵件。我用一個label顯示成功的文本,但在那個時候,它沒有顯示成功。發送電子郵件在C#使用端口號

的.aspx代碼:

<form id="form1" runat="server"> 

    Message from: <asp:TextBox ID="text1" runat="server"></asp:TextBox> 
    Message To: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    Message subject: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> 

    <asp:Button ID="b1" runat="server" OnClick="click" /> 

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
</form> 

.aspx.cs:

public void click(object sender, EventArgs e) 
{ 
    try 
    { 
     //mail message 
     MailMessage mM = new MailMessage(); 

     //Mail Address 
     mM.From = new MailAddress(text1.Text); 

     //emailid to send 
     mM.To.Add(TextBox1.Text); 

     //your subject line of the message 
     mM.Subject = "your subject line will go here."; 

     //now attached the file 
     //mM.Attachments.Add(new Attachment(@"C:\\attachedfile.jpg")); 

     //add the body of the email 
     mM.Body = "Your Body of the email."; 
     mM.IsBodyHtml = false; 

     //SMTP 
     SmtpClient SmtpServer = new SmtpClient(); 

     //your credential will go here 
     SmtpServer.Credentials = new 

     System.Net.NetworkCredential("username", "password"); 

     //port number to login yahoo server 
     SmtpServer.Port = 587; 

     //yahoo host name 
     SmtpServer.Host = "smtp.mail.yahoo.com"; 
     SmtpServer.EnableSsl = true; 

     SmtpServer.Send(mM); 
     Label1.Text = "successfull"; 
     //Send the email 

     //end of try block 
     //end of catch 
    } 
    catch(Exception ee){ 
     Console.Write(ee); 
    } 
} 
+2

您正在發佈您的密碼 –

+0

立即更改密碼。 – hometoast

+0

您正在捕捉異常並將其打印到控制檯。你能向我們展示正在打印的錯誤嗎?還是沒有錯誤? –

回答

0

我不認爲代碼本身有什麼不對。我幾乎使用與您的代碼相同的代碼,並且運行良好。

我覺得有什麼不對您的設置,請檢查:

  1. 如果您TextBox1的收件人的電子郵件地址早已存在
  2. 如果憑證的用戶名和密碼是正確的

而且我沒有在我的代碼中設置Port屬性。如果一切正確。請在此處顯示您的例外信息。