using System;
using System.Net.Mail;
namespace myMail
{
public class myEmail
{
/// <summary>
/// 系统电子邮件发送程式
/// </summary>
/// <param name="MailServer">指定SMTP服务器的名字</param>
/// <param name="UserID">账户名</param>
/// <param name="UserPWD">密码</param>
/// <param name="FromMailAddress">发送邮件的地址</param>
/// <param name="ToMailAddress">接收邮件的地址,多个地址用逗号分隔</param>
/// <param name="MailSubject">邮件主题</param>
/// <param name="MailBody">邮件内容</param>
/// <returns>发送成功,则返回true,否则返回false</returns>
public static bool sendMail(string MailServer,string UserID,string UserPWD,string FromMailAddress,string ToMailAddress,string MailSubject,string MailBody)
{
try
{
System.Net.Mail.SmtpClient client = new SmtpClient(MailServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(UserID, UserPWD);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage(FromMailAddress, ToMailAddress, MailSubject, MailBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
return true;
}
catch
{
return false;
}
}
}
}
using System.Net.Mail;
namespace myMail
{
public class myEmail
{
/// <summary>
/// 系统电子邮件发送程式
/// </summary>
/// <param name="MailServer">指定SMTP服务器的名字</param>
/// <param name="UserID">账户名</param>
/// <param name="UserPWD">密码</param>
/// <param name="FromMailAddress">发送邮件的地址</param>
/// <param name="ToMailAddress">接收邮件的地址,多个地址用逗号分隔</param>
/// <param name="MailSubject">邮件主题</param>
/// <param name="MailBody">邮件内容</param>
/// <returns>发送成功,则返回true,否则返回false</returns>
public static bool sendMail(string MailServer,string UserID,string UserPWD,string FromMailAddress,string ToMailAddress,string MailSubject,string MailBody)
{
try
{
System.Net.Mail.SmtpClient client = new SmtpClient(MailServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(UserID, UserPWD);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage(FromMailAddress, ToMailAddress, MailSubject, MailBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
return true;
}
catch
{
return false;
}
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/2f60c0bc47d4178ac5e2b807936153ff.gif)