我有两种发送电子邮件的方式。一个人“静静地”发送电子邮件,并且闪电般快速,另一个比西伯利亚糖蜜慢。但是,我们需要后者,因为我们希望允许用户添加和/或编辑内容,收件人等。
以下是快速但现在过时的方式:
public static void SendEmail(String Recipients,
String Sender,
String Subject,
String Body,
String SMTPHost)
{
try
{
var message = new MailMessage();
string[] recipients = Recipients.Split(';');
foreach (string recipient in recipients)
{
message.To.Add(recipient);
}
message.Subject = Subject;
message.From = new MailAddress(Sender);
message.Body = Body;
if (String.IsNullOrWhiteSpace(SMTPHost))
{
SMTPHost = "localhost";
}
var smtp = new SmtpClient(SMTPHost);
smtp.Send(message);
} catch (Exception e)
{
log.Error(e, e);
}
}
......这是新的但又缓慢的方式:
public static void SendEmail(String Recipients,
String Subject,
String Body)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = string.Format("mailto:{0}?subject={1}&body={2}", Recipients, Subject, Body);
proc.Start();
}
有没有办法加快后一种调用默认电子邮件客户端的方式(在我们的案例中是Outlook)?
答案 0 :(得分:1)