我的代码是:
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("ashwanirawat22@gmail.com"));
//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>
<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,yahoo等邮件我还没有收到。如何在我的帐户中收到所有帐号????
答案 0 :(得分:1)
为了发送和接收不同提供商的邮件,您必须更改smtp.Host
属性。例如,
SmtpServer.Host = "smtp.mail.yahoo.com";
SmtpServer.Host = "smtp.live.com";
分别从雅虎发送并直播...