本文整理汇总了C#中MimeKit.MimeMessage.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# MimeMessage.Prepare方法的具体用法?C# MimeMessage.Prepare怎么用?C# MimeMessage.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MimeKit.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.Prepare方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
void Send (FormatOptions options, MimeMessage message, MailboxAddress sender, IList<MailboxAddress> recipients, CancellationToken cancellationToken, ITransferProgress progress)
{
CheckDisposed ();
if (!IsConnected)
throw new ServiceNotConnectedException ("The SmtpClient is not connected.");
var format = options.Clone ();
format.International = format.International || sender.IsInternational || recipients.Any (x => x.IsInternational);
format.HiddenHeaders.Add (HeaderId.ContentLength);
format.HiddenHeaders.Add (HeaderId.ResentBcc);
format.HiddenHeaders.Add (HeaderId.Bcc);
format.NewLineFormat = NewLineFormat.Dos;
if (format.International && (Capabilities & SmtpCapabilities.UTF8) == 0)
throw new NotSupportedException ("The SMTP server does not support the SMTPUTF8 extension.");
if (format.International && (Capabilities & SmtpCapabilities.EightBitMime) == 0)
throw new NotSupportedException ("The SMTP server does not support the 8BITMIME extension.");
// prepare the message
if ((Capabilities & SmtpCapabilities.BinaryMime) != 0)
message.Prepare (EncodingConstraint.None, MaxLineLength);
else if ((Capabilities & SmtpCapabilities.EightBitMime) != 0)
message.Prepare (EncodingConstraint.EightBit, MaxLineLength);
else
message.Prepare (EncodingConstraint.SevenBit, MaxLineLength);
// figure out which SMTP extensions we need to use
var visitor = new ContentTransferEncodingVisitor (capabilities);
visitor.Visit (message);
var extensions = visitor.SmtpExtensions;
if (format.International)
extensions |= SmtpExtension.UTF8;
try {
// Note: if PIPELINING is supported, MailFrom() and RcptTo() will
// queue their commands instead of sending them immediately.
MailFrom (message, sender, extensions, cancellationToken);
var unique = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
foreach (var recipient in recipients) {
if (unique.Add (recipient.Address))
RcptTo (message, recipient, cancellationToken);
}
// Note: if PIPELINING is supported, this will flush all outstanding
// MAIL FROM and RCPT TO commands to the server and then process all
// of their responses.
FlushCommandQueue (sender, recipients, cancellationToken);
if ((extensions & SmtpExtension.BinaryMime) != 0)
Bdat (format, message, cancellationToken, progress);
else
Data (format, message, cancellationToken, progress);
} catch (ServiceNotAuthenticatedException) {
// do not disconnect
throw;
} catch (SmtpCommandException) {
Reset (cancellationToken);
throw;
} catch {
Disconnect ();
throw;
}
}