//aspx.cs file
protected void SendButton_Click(object sender, EventArgs e)
{
MailHelper.SendMailMessage("[email protected]", "[email protected]", "", "", "Sample Subject", "Sample body of text for mail message");
}
//MailHelper.cs
using System.Net.Mail;
public class MailHelper
{
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if ((bcc != null) && (bcc != string.Empty))
{
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
if ((cc != null) && (cc != string.Empty))
{
mMailMessage.CC.Add(new MailAddress(cc));
}
mMailMessage.Subject = subject;
mMailMessage.Body = body;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
SmtpClient mSmtpClient = new SmtpClient("127.0.0.1");
mSmtpClient.Send(mMailMessage);//Error here
}
}
我在mSmtpClient.Send(mMailMessage)
錯誤。無法連接到SMTP服務器
你能幫我嗎?
什麼是錯誤信息?這是你從標題中刪除的嗎? – Kev 2011-05-21 09:27:58
現在我在上述行中看到本標題中提到的錯誤。 – Naresh 2011-05-21 09:35:05
實際上你的代碼運行在同一臺機器上有SMTP服務器嗎? – Kev 2011-05-21 09:37:42