#region SendMails
/// <summary> ///根据传入的内容发送邮件。MessageTo接收者。若多个可用";"隔开.MessageSubject邮件主题。MessageBody邮件内容 /// </summary>
public static bool SendMails(string MessageTo, string MessageCC, string MessageSubject, string MessageBody)
{ //from@vdis.cn servicetransfer@vdis.cn
string sFrom = "jihao.pan@soyisoft.com"; //邮箱
string spass = "123456"; //密码
try
{
if (MessageTo != "")
{
string[] mailtos = MessageTo.Split(';');
string MessageToMain = MessageTo;
if (mailtos.Length > 1)
{
MessageToMain = mailtos[0];
}
MailAddress from = new MailAddress(sFrom);
MailAddress to = new MailAddress(MessageToMain);
MailMessage message = new MailMessage(from, to);
//多个主送
for (int i = 1; i < mailtos.Length; i++)
{
message.To.Add(new MailAddress(mailtos[i]));
}
//多个抄送
if (MessageCC != "")
{
string[] mailccs = MessageCC.Split(';');
foreach (string mailcc in mailccs)
{
message.CC.Add(new MailAddress(mailcc));
}
}
message.Subject = MessageSubject; //发送邮件的标题
message.Body = MessageBody; //发送邮件的内容
if (MessageSubject.IndexOf("重要") > -1) //只有重要的才加上优先级别。
{
message.Priority = MailPriority.High; //发送邮件的优先等级
}
message.IsBodyHtml = true;
//string strSC = "smtp." + sFrom.Substring(sFrom.IndexOf("@") + 1);
string strSC = "smtp.ee-post.com";
SmtpClient client = new SmtpClient(strSC);
client.UseDefaultCredentials = false;
client.Port = 25;
client.Credentials = new NetworkCredential(sFrom, spass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
return true;
}
else
{
return false;
}
}
catch (InvalidOperationException io)
{
throw io;
}
catch (SmtpException se)
{
throw se;
}
}
/// <summary> ///根据传入的内容发送邮件。MessageTo接收者。若多个可用";"隔开.MessageSubject邮件主题。MessageBody邮件内容 /// </summary>
public static bool SendMails(string sFrom, string spass, string MessageTo, string MessageCC, string MessageSubject, string MessageBody)
{
try
{
if (MessageTo != "")
{
string[] mailtos = MessageTo.Split(';');
string MessageToMain = MessageTo;
if (mailtos.Length > 1)
{
MessageToMain = mailtos[0];
}
MailAddress from = new MailAddress(sFrom);
MailAddress to = new MailAddress(MessageToMain);
MailMessage message = new MailMessage(from, to);
//多个主送
for (int i = 1; i < mailtos.Length; i++)
{
message.To.Add(new MailAddress(mailtos[i]));
}
//多个抄送
if (MessageCC != "")
{
string[] mailccs = MessageCC.Split(';');
foreach (string mailcc in mailccs)
{
message.CC.Add(new MailAddress(mailcc));
}
}
message.Subject = MessageSubject; //发送邮件的标题
message.Body = MessageBody; //发送邮件的内容
if (MessageSubject.IndexOf("重要") > -1) //只有重要的才加上优先级别。
{
message.Priority = MailPriority.High; //发送邮件的优先等级
}
message.IsBodyHtml = true;
//string strSC = "smtp." + sFrom.Substring(sFrom.IndexOf("@") + 1);
string strSC = "mailgot.it.volvo.com";
SmtpClient client = new SmtpClient(strSC);
client.UseDefaultCredentials = true;
client.Port = 25;
//client.Credentials = new NetworkCredential("M003489", "dell6000");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
return true;
}
else
{
return false;
}
}
catch (InvalidOperationException io)
{
throw io;
}
catch (SmtpException se)
{
throw se;
}
}
#endregion