MailAddress from = new MailAddress("[email protected]", "Ben Miller"); MailAddress to = new MailAddress("[email protected]", "Jane Clayton"); MailMessage message = new MailMessage(from, to); // message.Subject = "Using the SmtpClient class."; message.Subject = "Using the SmtpClient class."; message.Body = @"Using this feature, you can send an e-mail message from an application very easily."; // Add a carbon copy recipient. MailAddress copy = new MailAddress("[email protected]"); message.CC.Add(copy); SmtpClient client = new SmtpClient(server); // Include credentials if the server requires them. client.Credentials = CredentialCache.DefaultNetworkCredentials; Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {1}.", to.Address, client.Host); client.Send(message);
MailAddress from = new MailAddress("[email protected]", "Ben Miller");
MailAddress to = new MailAddress("[email protected]", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
// message.Subject = "Using the SmtpClient class.";
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
// Add a carbon copy recipient.
MailAddress copy = new MailAddress("[email protected]");
message.CC.Add(copy);
SmtpClient client = new SmtpClient(server);
// Include credentials if the server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {1}.",
to.Address, client.Host);
client.Send(message);
2 也可以使用CDO组件
比如gmail邮箱/// <summary>
/// 使用Gmail邮箱发送邮件
/// </summary>
/// <param name="From">指定发送者的Gmail邮箱</param>
/// <param name="Password">邮箱的密码</param>
/// <param name="To">收件人的地址,多个用户用分号分割</param>
/// <param name="Cc">抄送人的地址,多个用户用分号分割</param>
/// <param name="Bcc">密送者的地址,多个用户用分号分割</param>
/// <param name="Subject">邮件的主题</param>
/// <param name="Body">邮件的内容</param>
/// <returns>返回发送结果</returns>
public static string sendMail(string From, string Password, string To, string Cc, string Bcc, string Subject, string Body)
{
// Mail initialization
MailMessage mailMsg = new MailMessage();
mailMsg.From = From;
mailMsg.To = To;
mailMsg.Cc = Cc;
mailMsg.Bcc = Bcc;
mailMsg.Subject = Subject;
mailMsg.BodyFormat = MailFormat.Html;
mailMsg.Body = Body;
mailMsg.Priority = MailPriority.High;
// Smtp configuration
SmtpMail.SmtpServer = "smtp.gmail.com";
// - smtp.gmail.com use smtp authentication
mailMsg.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
From);
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
Password);
// - smtp.gmail.com use port 465 or 587
mailMsg.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
// - smtp.gmail.com use STARTTLS (some call this SSL)
mailMsg.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
// try to send Mail
try
{
SmtpMail.Send(mailMsg);
return "信息发送成功,请耐心等待回复";
}
catch (Exception ex)
{
return "发送错误:以下是错误信息:<br>" + ex.Message;
}
}:
{
bool strSucess = true;
System.Net.Mail.SmtpClient cln = new System.Net.Mail.SmtpClient(strSmtpServer);
cln.UseDefaultCredentials = false;
cln.Credentials = new System.Net.NetworkCredential(strUser, strPassword);//验证身份
cln.DeliveryMethod = SmtpDeliveryMethod.Network;//指定邮件通过smtp服务器发送
MailMessage mes = new MailMessage(strFrom,strTo,title,strContent);//邮件内容
mes.SubjectEncoding = Encoding.GetEncoding("GB2312");
mes.BodyEncoding = Encoding.GetEncoding("GB2312");
mes.IsBodyHtml = true;
try
{
cln.Send(mes);
}
catch (Exception ee)
{
strSucess = false;
}
return strSucess;
}
你这种法邮件的方法 最后用户接受到的效果是不是这样啊?
比如[email protected] 通过网站发送给 [email protected] 最后的效果是不是这样"邮件发送人:[email protected]; 接收人:[email protected];内容:....."
我使用GMAIL 可以不~~~~ 我想要这种效果 比如[email protected] 通过网站发送给 [email protected] 最后的效果要这样"邮件发送人:[email protected]; 接收人:[email protected];内容:....."