2013-03-12 82 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"; 

来自雅虎分别发送和生活......

相关问题