我正在尝试使用以下asp.net代码从localhost发送邮件..但电子邮件发送失败..
为什么会这样/ ???
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
string name = TextBox1.Text.ToString();
string contact = TextBox2.Text.ToString();
mail.To.Add("email@gmail.com");
mail.From = new MailAddress(name.Trim());
mail.Subject = "In line image test";
mail.Body = "Hello email...." +name.Trim() +", "+contact.Trim();
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("127.0.0.1");
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Host = "127.0.0.1";
client.Port = 25;
NetworkCredential credentials = new NetworkCredential("email@gmail.com", "abc");
client.Credentials = credentials;
try
{
client.Send(mail);
}
catch
{
Button1.Text = "Fail";
}
}
提前致谢..
答案 0 :(得分:2)
试试这个
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
client.Send(mail);
答案 1 :(得分:0)
首先在本地系统中设置SMTP服务器,然后点击此链接 http://www.arialsoftware.com/SetupSMTPServer.htm
然后你试试你的代码,如果你看到问题尝试整理,有人可以帮助你。
答案 2 :(得分:0)
请在Web.Config
档案
<system.net>
<mailSettings>
<smtp from="FROM EMAIL ADDRESS">
<network host="SERVER IP" userName="USER NAME" password="PASSWORD" port="25"/>
</smtp>
</mailSettings>
</system.net>
希望它对你有所帮助!