//aspx.cs file
protected void SendButton_Click(object sender, EventArgs e)
{
MailHelper.SendMailMessage("naresh7590@gmail.com", "cheekucheekuarena@gmail.com", "", "", "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)
.
你能帮我吗?