110,571
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 类公有静态方法,发送邮件
/// </summary>
/// <param name="recipients">收件人 </param>
/// <param name="subject">主题 </param>
/// <param name="body">邮件主体 </param>
public static void SendEmail(string recipients, string subject, string body)
{
string addressFrom = "abc@gail.com";
string userID = "abc";
string userPassword = "***";
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
System.Net.NetworkCredential crendetial = new NetworkCredential(userID, userPassword);
mailClient.Credentials = crendetial;
MailMessage message = new MailMessage(addressFrom, recipients, subject, body);
message.IsBodyHtml = true;
mailClient.Send(message);
}
private static void sendMail()
{
string smtpServer = "smtp.gmail.com";//服务器
int smtpPort = 587;//端口
string userAccount = "";//用户名
string userPassword = "";//密码
string userName = "";//发件人名称
string EmailAddress = "";//发件邮箱
string strto = "";//目的邮箱
string strSubject = "";//主题
string strBody = "";//内容
System.Net.Mail.SmtpClient client = new SmtpClient(smtpServer, smtpPort);
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(userAccount, userPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailAddress fromEmal = new MailAddress(EmailAddress, userName);
MailAddress toEmail = new MailAddress(strto);
System.Net.Mail.MailMessage message = new MailMessage(fromEmal, toEmail);
message.Subject = strSubject;
message.Body = strBody;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}
string emailname = System.Configuration.ConfigurationSettings.AppSettings["emailname"].ToString();
string emailpassword = System.Configuration.ConfigurationSettings.AppSettings["emailpassword"].ToString();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com");
client.Port = 995;
//client.EnableSsl = true ;
client.Credentials = new System.Net.NetworkCredential(emailname, emailpassword);
SmtpClient sc = new SmtpClient("smtp.163.com");
//sc.Port = 465;
//sc.EnableSsl = true;
sc.Credentials = new System.Net.NetworkCredential(emailname, emailpassword);
MailAddress addressFrom = new MailAddress(emailname, "CRM系统管理E-MAIL");
MailAddress addressTo = new MailAddress(toueremail, tousername);
System.Net.Mail.MailMessage message = new MailMessage(addressFrom, addressTo);
message.Subject = caption;
message.Body = "亲爱的" + tousername + "您好!<br/>\n" + text;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
string msg = "";
try
{
client.Send(message); //发送邮件
//sc.Send(message);
}
catch (Exception e)
{
msg = e.Message + ",邮件没有发送成功";
}
return msg;