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


C# EmailMessage.LoadFromConfig方法代码示例

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


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

示例1: CreateMessage

        /// <summary>
        /// Creates the aspNET EmailMessage object based on mail information
        /// we've alread got. Construct the message from html, and then spesify
        /// that the images should be attached inline.
        /// </summary>
        /// <param name="mailInfo">Mail info.</param>
        /// <returns></returns>
        private EmailMessage CreateMessage(MailInformation mailInfo)
        {
            if (_log.IsDebugEnabled())
                _log.Debug("Begin CreateMessage. Base Url: {0}", mailInfo.BaseUrl);

            EmailMessage email = new EmailMessage();
            HtmlUtility utility = new HtmlUtility(email);

            // Swallow exceptions if configured
            if (Configuration.NewsLetterConfiguration.DisableExceptionsInMailRendering == true)
                email.ThrowException = false;

            // Troubleshooting needs logging
            if (Configuration.NewsLetterConfiguration.ExtendedLogFile != null)
            {
                // Be careful with logging, it will generate large amounts of log data
                email.LogInMemory = false;
                email.LogPath = EPiServer.Global.BaseDirectory + Configuration.NewsLetterConfiguration.ExtendedLogFile;
                email.LogDebugStatements = true;
                email.LogBody = true;
                email.Logging = true;
            }

            // set all relative links contained in the html to this url
            string baseUrl = SiteDefinition.Current.SiteUrl.ToString();

            if (string.IsNullOrEmpty(mailInfo.BaseUrl) == false)
                baseUrl = mailInfo.BaseUrl;

            // Resolves Hrefs to their absolute value, this means
            // no urls in the html will be relative (which can be a pain
            // depending on the markup
            utility.ResolveHrefs = true;

            // Clean html, remove tags and content we do not want or need
            utility.HtmlRemovalOptions = HtmlRemovalOptions.AppletTag |
                                        HtmlRemovalOptions.EmbedTag |
                                        HtmlRemovalOptions.NoScriptTag |
                                        HtmlRemovalOptions.ObjectTag |
                                        HtmlRemovalOptions.ParamTag |
                                        HtmlRemovalOptions.Scripts |
                                        HtmlRemovalOptions.ViewState |
                                        HtmlRemovalOptions.EventArgument |
                                        HtmlRemovalOptions.EventTarget;

            // Load the html mail
            utility.LoadString(mailInfo.BodyHtml, baseUrl);

            // Set the UrlContent base
            utility.SetUrlContentBase = false;

            // Set the basetag in the html
            utility.SetHtmlBaseTag = true;

            // Embed the images into the email message, using the
            // content id as a src reference. Change this if you do
            // not want images to be part of the message
            utility.EmbedImageOption = EmbedImageOption.ContentId;

            // If you have problems loading images, disable exceptions
            // if (utility.ParentMessage != null)
            //    utility.ParentMessage.ThrowException = false;

            //render the Html so it is properly formatted for email
            utility.Render();

            //render an EmailMessage with appropriate text and html parts
            email = utility.ToEmailMessage();

            //load remaining properties from web.config
            email.LoadFromConfig();

            // Try to get these encodings correct
            email.ContentTransferEncoding = MailEncoding.QuotedPrintable;

            // Using utf-8 would have been nice, but utf-8 is not widely
            // adopted by email clients it seems.
            // email.CharSet = "utf-8";

            // Using iso 8859-1 hotmail will show Norwegian characters
            // even if the user runs with english settings
            // Hotmail needs this
            email.CharSet = "iso-8859-1";

            // Override with our own values
            email.Subject = mailInfo.Subject;
            email.From = mailInfo.From;
            email.TextBodyPart = mailInfo.BodyText;

            if (_log.IsDebugEnabled())
                _log.Debug("Rendered Mail Message: {0}", email.Subject);

            return email;
//.........这里部分代码省略.........
开发者ID:tsolbjor,项目名称:Newsletter,代码行数:101,代码来源:MailSenderAdvIntellect.cs


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