我想从雅虎发送电子邮件到雅虎 bt 发送失败。我用网络收到。请查看我的代码凭据。没有异常或错误,但是当打开邮箱时,没有电子邮件。我使用了一个label
which show succesfull 文本,但当时它没有显示成功。
.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);
}
}