当前位置: 首页>>代码示例>>C#>>正文


C# MailMessage.Populate方法代码示例

本文整理汇总了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
                }
            }
        }
开发者ID:bugjohnyang,项目名称:YAFNET,代码行数:50,代码来源:YafSendMailThreaded.cs

示例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
                }
            }
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:46,代码来源:YafSendMailThreaded.cs

示例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 });
        }
开发者ID:geoDarkAngel,项目名称:YAFNET,代码行数:37,代码来源:ISendMailExtensions.cs


注:本文中的System.Net.Mail.MailMessage.Populate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。