本文整理汇总了C#中System.Net.Mail.MailMessage.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.Populate方法的具体用法?C# MailMessage.Populate怎么用?C# MailMessage.Populate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了MailMessage.Populate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructMessageList
/// <summary>
/// The construct message list.
/// </summary>
/// <param name="mailMessages">
/// The mail messages.
/// </param>
/// <param name="mailList">
/// The mail list.
/// </param>
private void ConstructMessageList(IDictionary<MailMessage, Mail> mailMessages, IEnumerable<Mail> mailList)
{
// construct mail message list...
foreach (var mail in mailList.Where(x => x.ID > 0))
{
// Build a MailMessage
if (mail.FromUser.IsNotSet() || mail.ToUser.IsNotSet())
{
this.MailRepository.Delete(mail);
continue;
}
try
{
MailAddress toEmailAddress = mail.ToUserName.IsSet()
? new MailAddress(mail.ToUser, mail.ToUserName)
: new MailAddress(mail.ToUser);
MailAddress fromEmailAddress = mail.FromUserName.IsSet()
? new MailAddress(mail.FromUser, mail.FromUserName)
: new MailAddress(mail.FromUser);
var newMessage = new MailMessage();
mailMessages.Add(newMessage, mail);
newMessage.Populate(fromEmailAddress, toEmailAddress, mail.Subject, mail.Body, mail.BodyHtml);
}
catch (FormatException ex)
{
// incorrect email format -- delete this message immediately
this.MailRepository.Delete(mail);
#if (DEBUG)
this.Logger.Debug("Invalid Email Address: {0}".FormatWith(ex.ToString()), ex.ToString());
#else
this.Logger.Log(
null,
this,
"Invalid Email Address: {0}".FormatWith(ex.ToString()),
EventLogTypes.Warning);
#endif
}
}
}
示例2: ConstructMessageList
/// <summary>
/// The construct message list.
/// </summary>
/// <param name="mailMessages">
/// The mail messages.
/// </param>
/// <param name="mailList">
/// The mail list.
/// </param>
private void ConstructMessageList(IDictionary<MailMessage, TypedMailList> mailMessages, IEnumerable<TypedMailList> mailList)
{
// construct mail message list...
foreach (var mail in mailList.Where(x => x.MailID.HasValue))
{
// Build a MailMessage
if (mail.FromUser.IsNotSet() || mail.ToUser.IsNotSet())
{
LegacyDb.mail_delete(mail.MailID.Value);
continue;
}
try
{
MailAddress toEmailAddress = mail.ToUserName.IsSet()
? new MailAddress(mail.ToUser, mail.ToUserName)
: new MailAddress(mail.ToUser);
MailAddress fromEmailAddress = mail.FromUserName.IsSet()
? new MailAddress(mail.FromUser, mail.FromUserName)
: new MailAddress(mail.FromUser);
var newMessage = new MailMessage();
mailMessages.Add(newMessage, mail);
newMessage.Populate(fromEmailAddress, toEmailAddress, mail.Subject, mail.Body, mail.BodyHtml);
}
catch (FormatException ex)
{
// incorrect email format -- delete this message immediately
LegacyDb.mail_delete(mail.MailID);
this.Logger.Debug("Invalid Email Address: {0}".FormatWith(ex.ToString()));
#if (DEBUG)
this.Logger.Warn("Invalid Email Address: {0}".FormatWith(ex.ToString()), ex.ToString());
#endif
}
}
}
示例3: Send
/// <summary>
/// The send.
/// </summary>
/// <param name="sendMail">
/// The send mail.
/// </param>
/// <param name="fromAddress">
/// The from address.
/// </param>
/// <param name="toAddress">
/// The to address.
/// </param>
/// <param name="subject">
/// The subject.
/// </param>
/// <param name="bodyText">
/// The body text.
/// </param>
/// <param name="bodyHtml">
/// The body html.
/// </param>
public static void Send(
[NotNull] this ISendMail sendMail,
[NotNull] MailAddress fromAddress,
[NotNull] MailAddress toAddress,
[CanBeNull] string subject,
[CanBeNull] string bodyText,
[CanBeNull] string bodyHtml)
{
CodeContracts.VerifyNotNull(sendMail, "sendMail");
CodeContracts.VerifyNotNull(fromAddress, "fromAddress");
CodeContracts.VerifyNotNull(toAddress, "toAddress");
var mailMessage = new MailMessage();
mailMessage.Populate(fromAddress, toAddress, subject, bodyText, bodyHtml);
sendMail.SendAll(new List<MailMessage> { mailMessage });
}