• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mail.AlternateView类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.Mail.AlternateView的典型用法代码示例。如果您正苦于以下问题:C# AlternateView类的具体用法?C# AlternateView怎么用?C# AlternateView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AlternateView类属于System.Net.Mail命名空间,在下文中一共展示了AlternateView类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SendMail

        public static void SendMail(IEmailAccountSettingsProvider provider, string to, string subject, string body, Attachment attach, AlternateView av, bool isHTML)
        {
            if (provider.SmtpFrom != String.Empty)
            {
                if (provider.SmtpHost == "") return;
                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress(provider.SmtpFrom);
                mailMessage.To.Add(to);
                mailMessage.Subject = subject;
                if (av != null)
                    mailMessage.AlternateViews.Add(av);
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.Body = body;

                if (attach != null)
                    mailMessage.Attachments.Add(attach);
                if (isHTML)
                    mailMessage.IsBodyHtml = true;

                SmtpClient smtpClient = new SmtpClient();
                smtpClient.Host = provider.SmtpHost;
                smtpClient.Port = Convert.ToInt32(provider.SmtpPort);
                smtpClient.UseDefaultCredentials = Convert.ToBoolean(provider.SmtpCredentials);
                smtpClient.Credentials = new NetworkCredential(provider.SmtpUser, provider.SmtpPwd);
                smtpClient.EnableSsl = Convert.ToBoolean(provider.SmtpSSL);
                smtpClient.Send(mailMessage);
            }
        }
开发者ID:felixthehat,项目名称:Limo,代码行数:28,代码来源:EmailHelper.cs


示例2: Execute

        public MailAttributes Execute(MailAttributes mailAttributes)
        {
            var newMailAttributes = new MailAttributes(mailAttributes);

            foreach (var view in mailAttributes.AlternateViews)
            {
                using (var reader = new StreamReader(view.ContentStream))
                {
                    var body = reader.ReadToEnd();

                    if (view.ContentType.MediaType == MediaTypeNames.Text.Html)
                    {
                        var inlinedCssString = PreMailer.MoveCssInline(body);

                        byte[] byteArray = Encoding.UTF8.GetBytes(inlinedCssString.Html);
                        var stream = new MemoryStream(byteArray);
                        
                        var newAlternateView = new AlternateView(stream, MediaTypeNames.Text.Html);
                        newMailAttributes.AlternateViews.Add(newAlternateView);
                    }
                    else
                    {
                        newMailAttributes.AlternateViews.Add(view);
                    }
                }
            }

            return newMailAttributes;
        }
开发者ID:CodeFork,项目名称:ActionMailerNext,代码行数:29,代码来源:InlineCssPostProcessor.cs


示例3: GetSerializeableAlternateView

        internal static SerializeableAlternateView GetSerializeableAlternateView(AlternateView av)
        {
            if (av == null)
                return null;

            var sav = new SerializeableAlternateView();

            sav._baseUri = av.BaseUri;
            sav._contentId = av.ContentId;

            if (av.ContentStream != null)
            {
                var bytes = new byte[av.ContentStream.Length];
                av.ContentStream.Read(bytes, 0, bytes.Length);
                sav._contentStream = new MemoryStream(bytes);
            }

            sav._contentType = SerializeableContentType.GetSerializeableContentType(av.ContentType);

            foreach (LinkedResource lr in av.LinkedResources)
                sav._linkedResources.Add(SerializeableLinkedResource.GetSerializeableLinkedResource(lr));

            sav._transferEncoding = av.TransferEncoding;
            return sav;
        }
开发者ID:endeavour,项目名称:town-crier,代码行数:25,代码来源:SerializeableAlternateView.cs


示例4: AddImagesToView

 /// <summary>
 /// Adds recorded <see cref="LinkedResource"/> image references to the given <see cref="AlternateView"/>.
 /// </summary>
 public void AddImagesToView(AlternateView view)
 {
     foreach (var image in images)
     {
         view.LinkedResources.Add(image.Value);
     }
 }
开发者ID:habtamu,项目名称:postal,代码行数:10,代码来源:ImageEmbedder.cs


示例5: BuildMessageAndViews

        public static MailMessage BuildMessageAndViews(EmailMessage message, out AlternateView textView, out AlternateView htmlView)
        {
            var smtpMessage = new MailMessage { BodyEncoding = Encoding.UTF8, From = new MailAddress(message.From) };
            if(message.To.Count > 0) smtpMessage.To.Add(string.Join(",", message.To));
            if(message.ReplyTo.Count > 0) smtpMessage.ReplyToList.Add(string.Join(",", message.ReplyTo));
            if(message.Cc.Count > 0) smtpMessage.CC.Add(string.Join(",", message.Cc));
            if(message.Bcc.Count > 0) smtpMessage.Bcc.Add(string.Join(",", message.Bcc));
            
            htmlView = null;
            textView = null;

            if (!string.IsNullOrWhiteSpace(message.HtmlBody))
            {
                var mimeType = new ContentType("text/html");
                htmlView = AlternateView.CreateAlternateViewFromString(message.HtmlBody, mimeType);
                smtpMessage.AlternateViews.Add(htmlView);
            }

            if (!string.IsNullOrWhiteSpace(message.TextBody))
            {
                const string mediaType = "text/plain";
                textView = AlternateView.CreateAlternateViewFromString(message.TextBody, smtpMessage.BodyEncoding, mediaType);
                textView.TransferEncoding = TransferEncoding.SevenBit;
                smtpMessage.AlternateViews.Add(textView);
            }
            return smtpMessage;
        }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:27,代码来源:SmtpEmailProvider.cs


示例6: SerializableAlternateView

		private SerializableAlternateView(AlternateView view) {
			BaseUri = view.BaseUri;
			LinkedResources = new SerializableLinkedResourceCollection();
			foreach (LinkedResource res in view.LinkedResources)
				LinkedResources.Add(res);
			ContentId = view.ContentId;
			ContentStream = new MemoryStream();
			view.ContentStream.CopyTo(ContentStream);
			view.ContentStream.Position = 0;
			ContentType = view.ContentType;
			TransferEncoding = view.TransferEncoding;
		}
开发者ID:jesuswasrasta,项目名称:S22.Mail,代码行数:12,代码来源:SerializableAlternateView.cs


示例7: SendEmail

        public static void SendEmail(string FromEmail, string FromDispalyName, string ToList, string Subject, string HtmBody, string BCCList = "", AlternateView view = null)
        {
            MailMessage msgMail = new MailMessage();

            if (view != null)
                msgMail.AlternateViews.Add(view);

            if (!string.IsNullOrEmpty(ToList))
            {
                string[] toList = ToList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in toList)
                {
                    msgMail.To.Add(s);
                }
            }

            if (!string.IsNullOrEmpty(BCCList))
            {
                string[] bccList = BCCList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in bccList)
                {
                    msgMail.Bcc.Add(s);
                }
            }

            msgMail.From = new MailAddress(FromEmail, FromDispalyName, Encoding.UTF8);
            msgMail.Subject = Subject;
            msgMail.Body = HtmBody;
            msgMail.IsBodyHtml = true;
            msgMail.Priority = MailPriority.High;
            msgMail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;

            SmtpClient Client = new SmtpClient(SystemConfigs.SMTPServer)
                                    {
                                        Port = Convert.ToInt32(SystemConfigs.SMTPPort),
                                        EnableSsl = Convert.ToBoolean(SystemConfigs.SMTPIsSSL)
                                    };

            string UserName = SystemConfigs.SMTPUserName;
            string Password = SystemConfigs.SMTPPassword;
            if (!string.IsNullOrEmpty(UserName))
            {
                NetworkCredential Ceredentials = new NetworkCredential(UserName, Password);
                Client.Credentials = Ceredentials;
            }
            else
            {
                Client.Credentials = CredentialCache.DefaultNetworkCredentials;
            }
            Client.Send(msgMail);
        }
开发者ID:sinaaslani,项目名称:kids.bmi.ir,代码行数:51,代码来源:EMailing.cs


示例8: GetAlternateView

        internal AlternateView GetAlternateView()
        {
            var sav = new AlternateView(_contentStream);

            sav.BaseUri = _baseUri;
            sav.ContentId = _contentId;

            sav.ContentType = _contentType.GetContentType();

            foreach (SerializeableLinkedResource lr in _linkedResources)
                sav.LinkedResources.Add(lr.GetLinkedResource());

            sav.TransferEncoding = _transferEncoding;
            return sav;
        }
开发者ID:endeavour,项目名称:town-crier,代码行数:15,代码来源:SerializeableAlternateView.cs


示例9: GetAlternateView

		public AlternateView GetAlternateView()
		{
			var sav = new AlternateView(ContentStream)
			{
				BaseUri = BaseUri,
				ContentId = ContentId,
				ContentType = ContentType.GetContentType(),
				TransferEncoding = TransferEncoding,
			};

			foreach (var linkedResource in LinkedResources)
				sav.LinkedResources.Add(linkedResource.GetLinkedResource());

			return sav;
		}
开发者ID:dstimac,项目名称:revenj,代码行数:15,代码来源:SerializableAlternateView.cs


示例10: SerializableAlternateView

		public SerializableAlternateView(AlternateView alternativeView)
		{
			BaseUri = alternativeView.BaseUri;
			ContentId = alternativeView.ContentId;
			ContentType = new SerializableContentType(alternativeView.ContentType);
			TransferEncoding = alternativeView.TransferEncoding;

			if (alternativeView.ContentStream != null)
			{
				byte[] bytes = new byte[alternativeView.ContentStream.Length];
				alternativeView.ContentStream.Read(bytes, 0, bytes.Length);
				ContentStream = new MemoryStream(bytes);
			}

			foreach (var lr in alternativeView.LinkedResources)
				LinkedResources.Add(new SerializableLinkedResource(lr));
		}
开发者ID:dstimac,项目名称:revenj,代码行数:17,代码来源:SerializableAlternateView.cs


示例11: GenerateHtmlMessage

        private MailMessage GenerateHtmlMessage(string from, string to, string subject, string content, string[] attachmentFilepaths)
        {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(from);
            mail.To.Add(to);
            mail.Subject = subject;
            string body = null;
            if (attachmentFilepaths != null && attachmentFilepaths.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("MIME-Version: 1.0\r\n");
                sb.Append("Content-Type: multipart/mixed; boundary=unique-boundary-1\r\n");
                sb.Append("\r\n");
                sb.Append("This is a multi-part message in MIME format.\r\n");
                sb.Append("--unique-boundary-1\r\n");
                sb.Append("Content-Type: text/html\r\n");  //could use text/plain as well here if you want a plaintext message
                sb.Append("Content-Transfer-Encoding: 7Bit\r\n\r\n");
                sb.Append(content);
                if (!content.EndsWith("\r\n"))
                    sb.Append("\r\n");
                sb.Append("\r\n\r\n");
                foreach (string filepath in attachmentFilepaths)
                {
                    sb.Append(GenerateRawAttachement(filepath));
                }
                body = sb.ToString();
            }
            else
            {
                body = "Content-Type: text/html\r\nContent-Transfer-Encoding: 7Bit\r\n\r\n" + content;
            }
            //input your certification and private key.
            X509Certificate2 cert = new X509Certificate2("emailcertification.pfx", "6522626", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
            ContentInfo contentInfo = new ContentInfo(Encoding.UTF8.GetBytes(body));
            SignedCms signedCms = new SignedCms(contentInfo, false);
            CmsSigner Signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, cert);
            signedCms.ComputeSignature(Signer);
            byte[] signedBytes = signedCms.Encode();
            MemoryStream stream = new MemoryStream(signedBytes);
            AlternateView view = new AlternateView(stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
            mail.AlternateViews.Add(view);

            return mail;
        }
开发者ID:RandyCode,项目名称:SimpleTools,代码行数:44,代码来源:Program.cs


示例12: CreateView

    public static AlternateView CreateView( IHtmlDocument document )
    {
      var stream = new MemoryStream();
      document.Render( stream, Encoding.UTF8 );

      stream.Seek( 0, SeekOrigin.Begin );


      var resources = GetResources( document );

      var view = new AlternateView( stream, "text/html" );
      view.TransferEncoding = TransferEncoding.Base64;
      view.BaseUri = document.DocumentUri;

      foreach ( var r in resources )
        view.LinkedResources.Add( r );


      return view;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:20,代码来源:Program.cs


示例13: SetContent

        private void SetContent(bool allowUnicode)
        {
            //the attachments may have changed, so we need to reset the message
            if (_bodyView != null)
            {
                _bodyView.Dispose();
                _bodyView = null;
            }

            if (AlternateViews.Count == 0 && Attachments.Count == 0)
            {
                if (!string.IsNullOrEmpty(_body))
                {
                    _bodyView = AlternateView.CreateAlternateViewFromString(_body, _bodyEncoding, (_isBodyHtml ? MediaTypeNames.Text.Html : null));
                    _message.Content = _bodyView.MimePart;
                }
            }
            else if (AlternateViews.Count == 0 && Attachments.Count > 0)
            {
                MimeMultiPart part = new MimeMultiPart(MimeMultiPartType.Mixed);

                if (!string.IsNullOrEmpty(_body))
                {
                    _bodyView = AlternateView.CreateAlternateViewFromString(_body, _bodyEncoding, (_isBodyHtml ? MediaTypeNames.Text.Html : null));
                }
                else
                {
                    _bodyView = AlternateView.CreateAlternateViewFromString(string.Empty);
                }

                part.Parts.Add(_bodyView.MimePart);

                foreach (Attachment attachment in Attachments)
                {
                    if (attachment != null)
                    {
                        //ensure we can read from the stream.
                        attachment.PrepareForSending(allowUnicode);
                        part.Parts.Add(attachment.MimePart);
                    }
                }
                _message.Content = part;
            }
            else
            {
                // we should not unnecessarily use Multipart/Mixed
                // When there is no attachement and all the alternative views are of "Alternative" types.
                MimeMultiPart part = null;
                MimeMultiPart viewsPart = new MimeMultiPart(MimeMultiPartType.Alternative);

                if (!string.IsNullOrEmpty(_body))
                {
                    _bodyView = AlternateView.CreateAlternateViewFromString(_body, _bodyEncoding, null);
                    viewsPart.Parts.Add(_bodyView.MimePart);
                }

                foreach (AlternateView view in AlternateViews)
                {
                    //ensure we can read from the stream.
                    if (view != null)
                    {
                        view.PrepareForSending(allowUnicode);
                        if (view.LinkedResources.Count > 0)
                        {
                            MimeMultiPart wholeView = new MimeMultiPart(MimeMultiPartType.Related);
                            wholeView.ContentType.Parameters["type"] = view.ContentType.MediaType;
                            wholeView.ContentLocation = view.MimePart.ContentLocation;
                            wholeView.Parts.Add(view.MimePart);

                            foreach (LinkedResource resource in view.LinkedResources)
                            {
                                //ensure we can read from the stream.
                                resource.PrepareForSending(allowUnicode);

                                wholeView.Parts.Add(resource.MimePart);
                            }
                            viewsPart.Parts.Add(wholeView);
                        }
                        else
                        {
                            viewsPart.Parts.Add(view.MimePart);
                        }
                    }
                }

                if (Attachments.Count > 0)
                {
                    part = new MimeMultiPart(MimeMultiPartType.Mixed);
                    part.Parts.Add(viewsPart);

                    MimeMultiPart attachmentsPart = new MimeMultiPart(MimeMultiPartType.Mixed);
                    foreach (Attachment attachment in Attachments)
                    {
                        if (attachment != null)
                        {
                            //ensure we can read from the stream.
                            attachment.PrepareForSending(allowUnicode);
                            attachmentsPart.Parts.Add(attachment.MimePart);
                        }
                    }
//.........这里部分代码省略.........
开发者ID:geoffkizer,项目名称:corefx,代码行数:101,代码来源:MailMessage.cs


示例14: CreateAlternateViewFromString

		public static AlternateView CreateAlternateViewFromString (string content)
		{
			if (content == null)
				throw new ArgumentNullException ();
			MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (content));
			AlternateView av = new AlternateView (ms);
			av.TransferEncoding = TransferEncoding.QuotedPrintable;
			return av;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:AlternateView.cs


示例15: CreateAlternateView

 /// <summary>
 /// Creates the alternate view.
 /// </summary>
 /// <param name="view">The view.</param>
 /// <returns></returns>
 private AlternateView CreateAlternateView(MimeEntity view)
 {
     AlternateView alternateView = new AlternateView(view.Content, view.ContentType);
     alternateView.TransferEncoding = view.ContentTransferEncoding;
     alternateView.ContentId = TrimBrackets(view.ContentId);
     return alternateView;
 }
开发者ID:Termit1975,项目名称:sidepop,代码行数:12,代码来源:MimeEntity.cs


示例16: PopulateLinkedResource

        /// <summary>
        /// Adds a single LinkedResource to a mailPart
        /// </summary>
        public virtual LinkedResource PopulateLinkedResource(AlternateView mailPart, string contentId, string fileName)
        {
            var linkedResource = LinkedResourceProvider.Get(contentId, fileName);
            mailPart.LinkedResources.Add(linkedResource);

            return linkedResource;
        }
开发者ID:zanfar,项目名称:MvcMailer,代码行数:10,代码来源:MailerBase.cs


示例17: CreateAlternateViewFromString

 public static AlternateView CreateAlternateViewFromString(string content, Encoding contentEncoding, string mediaType)
 {
     AlternateView view = new AlternateView();
     view.SetContentFromString(content, contentEncoding, mediaType);
     return view;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:6,代码来源:AlternateView.cs


示例18: PopulateLinkedResources

        /// <summary>
        /// Adds LinkedResources to the mailPart
        /// </summary>
        public virtual List<LinkedResource> PopulateLinkedResources(AlternateView mailPart, Dictionary<string, string> resources)
        {
            if (resources == null || resources.Count == 0) {
                return new List<LinkedResource>();
            }

            var linkedResources = LinkedResourceProvider.GetAll(resources);
            linkedResources.ForEach(resource => mailPart.LinkedResources.Add(resource));

            return linkedResources;
        }
开发者ID:zanfar,项目名称:MvcMailer,代码行数:14,代码来源:MailerBase.cs


示例19: AddChildPartsToParent

        /// <summary>
        /// Add all attachments and alternative views from child to the parent
        /// </summary>
        /// <param name="child">child Object</param>
        /// <param name="parent">parent Object</param>
        private static void AddChildPartsToParent(MailMessageParser child, MailMessageParser parent)
        {
            ////add the child itself to the parent
            parent.Entities.Add(child);

            ////add the alternative views of the child to the parent
            if (null != child.AlternateViews)
            {
                foreach (AlternateView childView in child.AlternateViews)
                {
                    parent.AlternateViews.Add(childView);
                }
            }

            ////add the body of the child as alternative view to parent
            ////this should be the last view attached here, because the POP 3 MIME client
            ////is supposed to display the last alternative view
            if (child.MediaMainType == ServiceConstants.TEXT_MEDIA_MAIN_TYPE && null != child.ContentStream && null != child.Parent.ContentType && child.Parent.ContentType.MediaType.ToUpperInvariant() == ServiceConstants.MULTI_PART_MEDIA_TYPE)
            {
                AlternateView thisAlternateView = new AlternateView(child.ContentStream);
                thisAlternateView.ContentId = RemoveBrackets(child.ContentId);
                thisAlternateView.ContentType = child.ContentType;
                thisAlternateView.TransferEncoding = child.ContentTransferEncoding;
                parent.AlternateViews.Add(thisAlternateView);
            }

            ////add the attachments of the child to the parent
            if (null != child.Attachments)
            {
                foreach (Attachment childAttachment in child.Attachments)
                {
                    parent.Attachments.Add(childAttachment);
                }
            }
        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:40,代码来源:MimeReader.cs


示例20: AddChildPartsToParent

        /// <summary>
        /// Add all attachments and alternative views from child to the parent
        /// </summary>
        private void AddChildPartsToParent(RxMailMessage child, RxMailMessage parent)
        {
            //add the child itself to the parent
              parent.Entities.Add(child);

              //add the alternative views of the child to the parent
              if (child.AlternateViews!=null) {
            foreach (AlternateView childView in child.AlternateViews) {
              parent.AlternateViews.Add(childView);
            }
              }

              //add the body of the child as alternative view to parent
              //this should be the last view attached here, because the POP 3 MIME client
              //is supposed to display the last alternative view
              if (child.MediaMainType=="text" && child.ContentStream!=null &&
            child.Parent.ContentType!=null && child.Parent.ContentType.MediaType.ToLowerInvariant()=="multipart/alternative")
              {
            AlternateView thisAlternateView = new AlternateView(child.ContentStream);
            thisAlternateView.ContentId = RemoveBrackets(child.ContentId);
            thisAlternateView.ContentType = child.ContentType;
            thisAlternateView.TransferEncoding = child.ContentTransferEncoding;
            parent.AlternateViews.Add(thisAlternateView);
              }

              //add the attachments of the child to the parent
              if (child.Attachments!=null) {
            foreach (Attachment childAttachment in child.Attachments) {
              parent.Attachments.Add(childAttachment);
            }
              }
        }
开发者ID:eMerge-IT,项目名称:PriorityMobile,代码行数:35,代码来源:Pop3MimeClient.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mail.Attachment类代码示例发布时间:2022-05-26
下一篇:
C# Headers.Token类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap