2013-03-12 35 views
0

我的代碼是:我有Gmail帳戶接收電子郵件,但在asp.net C#不接收其他賬戶如雅虎,Hotmail等

using System.Net.Mail;<br/> 
using System.Net;<br/> 
public partial class Index : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 

} 
protected void home_btn_Click(object sender, ImageClickEventArgs e) 
{ 
    MailMessage msg = new MailMessage(); 
    msg.From = new MailAddress(home_mail.Text); 
    msg.To.Add(new MailAddress("[email protected]")); 
    //msg.CC.Add (new MailAddress(txtcc.Text)); 
    //msg.Subject = txtSubject.Text; 
    msg.Body = home_msg.Text; 
    msg.IsBodyHtml = false; 
    SmtpClient smtp = new SmtpClient(); 
    smtp.Host = "smtp.gmail.com"; 
    smtp.Credentials = new System.Net.NetworkCredential(home_mail.Text,home_pass.Text); 
    label1.Visible = true; 
    smtp.EnableSsl = true; 
    try 
    { 
     smtp.Send(msg); 
     label1.Text = "Email Send"; 

    } 
    catch 
    { 
     label1.Text = "Email Failed"; 
    } 
    home_msg.Text = ""; 
    home_mail.Text = ""; 
    home_pass.Text = ""; 
    } 
} 

HTML代碼:

Message: <asp:TextBox ID="home_msg" Rows="5" Columns="45" TextMode="MultiLine"runat="server"> 
</asp:TextBox><br/> 
From: <asp:TextBox ID="home_mail" runat="server" Height="30px" Width="380px"></asp:TextBox></div><br /> 
Password: 
<asp:TextBox ID="home_pass" runat="server" Height="30px" Width="380px" TextMode="Password"></asp:TextBox> 
&nbsp; <asp:ImageButton ID="home_btn" ImageUrl="~/images/button.png" runat="server" 
Height="30px" Width="75px" onclick="home_btn_Click" /> 
<asp:Label ID="label1" runat="server"></asp:Label> 

現在我的問題是我已經收到我的帳戶只有Gmail帳戶郵件,但其他帳戶,如hotmail,雅虎等郵件我還沒有收到。如何可以收到我帳戶中的所有帳戶郵件?

+1

你的問題的標題會談有關接收郵件,但你的代碼示例發送郵件。你能提供更多關於這裏實際問題的描述嗎? – Dutts 2013-03-12 08:20:05

+0

你是對的,那麼你可以幫我瞭解一下接收郵件的編碼。請寫下接收郵件的代碼。 – Ashwani 2013-03-12 08:28:40

+1

對不起,我不會爲你寫郵件客戶端,但是我可以幫你解決任何特定的編碼問題。 – Dutts 2013-03-12 08:29:31

回答

1

要以發送和接收郵件的形式提供不同的提供者,您必須更改smtp.Host屬性。例如,

SmtpServer.Host = "smtp.mail.yahoo.com"; 
SmtpServer.Host = "smtp.live.com"; 

來自雅虎分別發送和生活......

相關問題