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


C# MailMessage.GetBodyParts方法代码示例

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


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

示例1: Build

		public static List<FormPart> Build(MailMessage message, IDictionary<string, IDictionary<string, object>> recipientVariables)
		{
			if (message == null)
				return new List<FormPart>();

			var result = new List<FormPart>
			{
				new SimpleFormPart("from", message.From.ToString()),
				new SimpleFormPart("to",string.Join(", ", message.To)),
				new SimpleFormPart("subject", message.Subject),
			};

			if (recipientVariables != null)
			{
				result.Add(new SimpleFormPart("recipient-variables", JsonConvert.SerializeObject(recipientVariables)));
			}

			if (message.CC.Any())
				result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));

			if (message.Bcc.Any())
				result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));

			if(message.ReplyToList.Any())
				result.Add(new SimpleFormPart("h:Reply-To", string.Join(", ", message.ReplyToList)));

			result.AddRange(message.GetBodyParts());

			result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));

			return result;
		}
开发者ID:DeadlyEmbrace,项目名称:mnailgun,代码行数:32,代码来源:FormPartsBuilder.cs

示例2: Build

        public static List<FormPart> Build(MailMessage message)
        {
            if (message == null)
                return new List<FormPart>();

            var result = new List<FormPart>
            {
                new SimpleFormPart("from", message.From.ToString()),
                new SimpleFormPart("to",string.Join(", ", message.To)),
                new SimpleFormPart("subject", message.Subject)
            };

            if (message.CC.Any())
                result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));

            if (message.Bcc.Any())
                result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));

            result.AddRange(message.GetBodyParts());

            result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));

            return result;
        }
开发者ID:jakerad1979,项目名称:mnailgun,代码行数:24,代码来源:FormPartsBuilder.cs

示例3: Build

        public static List<FormPart> Build(MailMessage message, IDictionary<string, IDictionary<string, object>> recipientVariables)
        {
            if (message == null)
                return new List<FormPart>();

            var result = new List<FormPart>
            {
                new SimpleFormPart("from", message.From.ToString()),
                new SimpleFormPart("to",string.Join(", ", message.To)),
                new SimpleFormPart("subject", message.Subject),
            };

            if (recipientVariables != null)
            {
                result.Add(new SimpleFormPart("recipient-variables", JsonConvert.SerializeObject(recipientVariables)));
            }

            if (message.CC.Any())
                result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));

            if (message.Bcc.Any())
                result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));

            if(message.ReplyToList.Any())
                result.Add(new SimpleFormPart("h:Reply-To", string.Join(", ", message.ReplyToList)));

            // Check for the existence of any Mailgun-Variables headers
            if (message.Headers.AllKeys.Contains("X-Mailgun-Variables"))
            {
                // Grab the Mailgun variables header values
                var variableHeaders = message.Headers.GetValues("X-Mailgun-Variables");
                if (variableHeaders != null)
                {
                    // Iterate over the collection and add each tag header to the result
                    foreach (var variable in variableHeaders)
                    {
                        JObject customVar = JObject.Parse(variable);
                        foreach (var item in customVar)
                        {
                            result.Add(new SimpleFormPart(string.Format("v:{0}", item.Key), item.Value.ToString()));
                        }
                    }
                }
            }

            result.AddRange(message.GetBodyParts());

            // Check for the existense of any Mailgun Tag headers
            if (message.Headers.AllKeys.Contains("X-Mailgun-Tag"))
            {
                // Grab the Mailgun tag header values
                var tagHeaders = message.Headers.GetValues("X-Mailgun-Tag");
                if (tagHeaders != null)
                {
                    // Iterate over the collection and add each tag header to the result
                    foreach (var tag in tagHeaders)
                    {
                        result.Add(new SimpleFormPart("o:tag", tag));
                    }
                }
            }

            result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));

            return result;
        }
开发者ID:typesafe,项目名称:mnailgun,代码行数:66,代码来源:FormPartsBuilder.cs


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