本文整理汇总了C#中System.Net.Mail.MailMessage.ShouldNotBeNull方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.ShouldNotBeNull方法的具体用法?C# MailMessage.ShouldNotBeNull怎么用?C# MailMessage.ShouldNotBeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了MailMessage.ShouldNotBeNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendTask
/// <summary>
/// 메일을 비동기적으로 전송하는 Task{bool}을 빌드합니다.
/// </summary>
/// <param name="client">smtp client</param>
/// <param name="token">작업 취소용 Token</param>
/// <param name="message">mail message</param>
/// <param name="userToken"></param>
/// <returns>비동기 작업을 수행하는 Task{bool}</returns>
public static Task<bool> SendTask(this SmtpClient client, CancellationToken token, MailMessage message, object userToken = null) {
message.ShouldNotBeNull("message");
if(IsDebugEnabled)
log.Debug("비동기 방식으로 메일을 발송합니다... from=[{0}], recipients=[{1}], subject=[{2}], body=[{3}]",
message.From, message.To.CollectionToString(), message.Subject, message.Body.EllipsisChar(80));
return SendTaskInternal(client, token, userToken, tcs => client.SendAsync(message, tcs));
}
示例2: SendMessage
/// <summary>
/// Mail 보내기
/// </summary>
/// <param name="host">SMTP Host address.</param>
/// <param name="port">SMTP port</param>
/// <param name="message">mail message</param>
public static void SendMessage(string host, int port, MailMessage message) {
host.ShouldNotBeWhiteSpace("host");
message.ShouldNotBeNull("message");
if(IsDebugEnabled)
log.Debug("email을 전송합니다... host=[{0}], port=[{1}], message.Subject=[{2}]", host, port, message.Subject);
var mailClient = new SmtpClient(host, port);
mailClient.Send(message);
}