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


C# IEvent.ToHtmlPage方法代码示例

本文整理汇总了C#中IEvent.ToHtmlPage方法的典型用法代码示例。如果您正苦于以下问题:C# IEvent.ToHtmlPage方法的具体用法?C# IEvent.ToHtmlPage怎么用?C# IEvent.ToHtmlPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEvent的用法示例。


在下文中一共展示了IEvent.ToHtmlPage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMail

        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="ev" /> to the specified <paramref name="user" />. Returns
        /// <c>true</c> if the e-mail is successfully sent.
        /// </summary>
        /// <param name="ev">The application event to be sent to users.</param>
        /// <param name="user">The user to send the e-mail to.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="emailSender">The account that that will appear in the "From" portion of the e-mail.</param>
        /// <returns>Returns <c>true</c> if the e-mail is successfully sent; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ev" />, <paramref name="user" />, 
        /// <paramref name="appSettings" />, or <paramref name="emailSender" /> is null.</exception>
        private static bool SendMail(IEvent ev, IUserAccount user, IAppSetting appSettings, MailAddress emailSender)
        {
            #region Validation

            if (ev == null)
                throw new ArgumentNullException("ev");

            if (user == null)
                throw new ArgumentNullException("user");

            if (appSettings == null)
                throw new ArgumentNullException("appSettings");

            if (emailSender == null)
                throw new ArgumentNullException("emailSender");

            #endregion

            var emailWasSent = false;

            if (!IsValidEmail(user.Email))
            {
                return false;
            }

            var emailRecipient = new MailAddress(user.Email, user.UserName);
            try
            {
                using (var mail = new MailMessage(emailSender, emailRecipient))
                {
                    if (String.IsNullOrEmpty(ev.ExType))
                        mail.Subject = Resources.Email_Subject_When_No_Ex_Type_Present;
                    else
                        mail.Subject = String.Concat(Resources.Email_Subject_Prefix_When_Ex_Type_Present, " ", ev.ExType);

                    mail.Body = ev.ToHtmlPage();
                    mail.IsBodyHtml = true;

                    using (var smtpClient = new SmtpClient())
                    {
                        smtpClient.EnableSsl = appSettings.SendEmailUsingSsl;

                        // Specify SMTP server if it is specified. The server might have been assigned via web.config,
                        // so only update this if we have a config setting.
                        if (!String.IsNullOrEmpty(appSettings.SmtpServer))
                        {
                            smtpClient.Host = appSettings.SmtpServer;
                        }

                        // Specify port number if it is specified and it's not the default value of 25. The port
                        // might have been assigned via web.config, so only update this if we have a config setting.
                        int smtpServerPort;
                        if (!Int32.TryParse(appSettings.SmtpServerPort, out smtpServerPort))
                            smtpServerPort = Int32.MinValue;

                        if ((smtpServerPort > 0) && (smtpServerPort != 25))
                        {
                            smtpClient.Port = smtpServerPort;
                        }

                        smtpClient.Send(mail);
                    }

                    emailWasSent = true;
                }
            }
            catch (Exception ex2)
            {
                string eventMsg = String.Concat(ex2.GetType(), ": ", ex2.Message);

                if (ex2.InnerException != null)
                    eventMsg += String.Concat(" ", ex2.InnerException.GetType(), ": ", ex2.InnerException.Message);

                ev.EventData.Add(new KeyValuePair<string, string>(Resources.Cannot_Send_Email_Lbl, eventMsg));
            }

            return emailWasSent;
        }
开发者ID:Jiyuu,项目名称:galleryserverpro,代码行数:89,代码来源:EventController.cs


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