我正在尝试制作一个电子邮件页面部分,我在这个论坛中找到了一篇文章和一个答案,我在下面的代码中使用了它,但它仍然说发送邮件失败,我几乎不知道为什么?我需要帮助来寻找补救措施,为什么我的以下代码无法发送电子邮件。下面是我的代码供您参考。请告知...谢谢。
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.live.com"; //Im not sure about this,I just copy it from the article
client.Port = 4548; //This is my ASP.Net Development Server Port,Im not sure also if this is correct.
client.Credentials = new System.Net.NetworkCredential(
@"email_account",
@"email_password"); //Im not sure about this code if this correct, I just copy it
client.EnableSsl = true;
// create message
MailMessage message = new MailMessage();
message.From = new MailAddress(TextBox4.Text, "Mackmellow"); //Textbox4 is my email address
message.To.Add(new MailAddress(TextBox1.Text, "Mackmellow")); // Textbox1 is the email add I want to send
message.Subject = TextBox2.Text; //Textbox2 is my subject
message.Body = TextBox3.Text; // Textbox3 is my message
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// send message
try
{
client.Send(message);
}
catch (SmtpException ex)
{
Response.Write(ex.Message);
}
finally
{
// Clean up.
message.Dispose();
}
可以请更正我的代码并告诉我我缺少什么吗?提前致谢...