62,046
社区成员
发帖
与我相关
我的任务
分享
string strSmtpServer = smtpServer;
string strFrom = mailFrom;
string strMailProxyUser = mailProxyUser;
string strMailProxyPass = mailProxyPassword;
SmtpClient client = new SmtpClient(strSmtpServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strMailProxyUser, strMailProxyPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Timeout = 3000000;
MailAddress from = new MailAddress(strFrom);
MailAddress to = new MailAddress(strTo, strToDisplayName);
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
message.Subject = strSubject;
message.Body = strBody;
System.Net.Mail.Attachment attachment = null;
message.SubjectEncoding = Encoding.UTF8;
message.HeadersEncoding = Encoding.UTF8;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
if (attachmentFiles != null)
{
foreach (string files in attachmentFiles)
{
if (System.IO.File.Exists(files))
{
attachment = new System.Net.Mail.Attachment(files);
attachment.NameEncoding = Encoding.UTF8;
message.Attachments.Add(attachment);
}
}
}
try
{
client.Send(message);
}
catch (Exception ex)
{
DebugWrite("发送邮件出现问题了" + ex.ToString());
}
finally
{
foreach (Attachment item in message.Attachments)
{
item.Dispose();
}
if (attachment != null)
{
attachment.Dispose();
}
message.Dispose();
}