本文整理汇总了C#中SmtpClient.Close方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.Close方法的具体用法?C# SmtpClient.Close怎么用?C# SmtpClient.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubmitMail
private async Task SubmitMail(
SmtpServer oServer, SmtpMail oMail, string[] atts,
string bodyText, bool htmlBody, int index )
{
SmtpClient oSmtp = null;
try
{
oSmtp = new SmtpClient();
// oSmtp.TaskCancellationToken = m_cts.Token;
// oSmtp.Authorized += new SmtpClient.OnAuthorizedEventHandler(OnAuthorized);
oSmtp.Connected += OnConnected;
// oSmtp.Securing += new SmtpClient.OnSecuringEventHandler(OnSecuring);
//oSmtp.SendingDataStream +=
// new SmtpClient.OnSendingDataStreamEventHandler(OnSendingDataStream);
UpdateRecipientItem(index, "Preparing ...");
if ( !htmlBody )
{
oMail.TextBody = bodyText;
}
else
{
string html = bodyText;
html = "<html><head><meta charset=\"utf-8\" /></head><body style=\"font-family:Calibri;font-size: 15px;\">" + html + "<body></html>";
await oMail.ImportHtmlAsync(html,
Windows.ApplicationModel.Package.Current.InstalledLocation.Path,
ImportHtmlBodyOptions.ErrorThrowException | ImportHtmlBodyOptions.ImportLocalPictures
| ImportHtmlBodyOptions.ImportHttpPictures | ImportHtmlBodyOptions.ImportCss);
}
int count = atts.Length;
for (int i = 0; i < count; i++)
{
await oMail.AddAttachmentAsync(atts[i]);
}
UpdateRecipientItem(index, String.Format("Connecting {0} ...", oServer.Server));
oSmtp.Tag = index;
// You can genereate a log file by the following code.
// oSmtp.LogFileName = "ms-appdata:///local/smtp.txt";
IAsyncAction asynCancelSend = oSmtp.SendMailAsync(oServer, oMail);
m_cts.Token.Register(() => asynCancelSend.Cancel());
await asynCancelSend;
Interlocked.Increment(ref m_success);
UpdateRecipientItem(index, "Completed");
}
catch (Exception ep)
{
oSmtp.Close();
string errDescription = ep.Message;
UpdateRecipientItem(index, errDescription);
Interlocked.Increment(ref m_failed);
}
}