You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
using Stone.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Stone.WinService
|
|
{
|
|
public class F_Mail
|
|
{
|
|
public static void SendMail(string MailBody)
|
|
{
|
|
string MailTitle = "安通林EDI邮件报警";
|
|
SendMail(MailTitle, MailBody);
|
|
}
|
|
|
|
public static void SendMail(string filename, string MailTitle, string MailBody)
|
|
{
|
|
|
|
MailBody += "<br><br>";
|
|
MailBody += $"文件:{filename}<br>";
|
|
MailBody += $"时间:{DateTime.Now}";
|
|
|
|
SendMail(MailTitle, MailBody);
|
|
}
|
|
|
|
|
|
public static void SendMail(string MailTitle, string MailBody)
|
|
{
|
|
try
|
|
{
|
|
string To = MyAppconfig.ReadValue("MailReceiver");
|
|
string From = MyAppconfig.ReadValue("MailSender");
|
|
string Server = MyAppconfig.ReadValue("MailServer");
|
|
string UserName = MyAppconfig.ReadValue("MailUserName");
|
|
string Password = MyAppconfig.ReadValue("MailPassword");
|
|
int Port = Convert.ToInt32(MyAppconfig.ReadValue("MailPort"));
|
|
|
|
if (Server == "") return;
|
|
|
|
MySmtpMail SmtpMail = new MySmtpMail(To, From, MailBody, MailTitle, Server, UserName, Password, true, Port, true, "");
|
|
//SmtpMail.SendAsync(smtp_SendCompleted);
|
|
SmtpMail.Send();
|
|
|
|
//MyLogger.Write(MailTitle + "\r\n" + MailBody);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MyLogger.Write(ex.Message);
|
|
}
|
|
}
|
|
|
|
// 回调函数
|
|
public static void smtp_SendCompleted(object sender, AsyncCompletedEventArgs e)
|
|
{
|
|
if (e.Cancelled) //邮件发送被取消
|
|
{
|
|
MyLogger.Write("邮件被取消");
|
|
}
|
|
if (e.Error != null) //邮件发送失败
|
|
{
|
|
MyLogger.Write("邮件发送失败,原因:" + e.Error.ToString());
|
|
}
|
|
else //发送成功
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|