Click here to Skip to main content
15,896,606 members
Articles / Web Development / HTML

MailMergeLib - A Mail Client Library for .NET

Rate me:
Please Sign up or sign in to vote.
4.95/5 (131 votes)
5 Nov 2017MIT9 min read 843.6K   10.2K   542  
MailMergeLib is an SMTP template mail client library written in C# which provides comfortable mail merge capabilities and SMTP fail-over features. If works on .NET Framework and .NET Core.
using System.Net.Mail;
using System.Net.Mime;

namespace MailMergeLib
{
	internal class PlainBodyBuilder : BodyBuilderBase
	{
		private readonly string _plainText;

		public PlainBodyBuilder(string plainText)
		{
			_plainText = plainText;
		}


		/// <summary>
		/// Gets the ready made body part for a mail message.
		/// </summary>
		public override AlternateView Body
		{
			get
			{
				AlternateView plainBody = AlternateView.CreateAlternateViewFromString(_plainText,
				                                                                      CharacterEncoding, MediaTypeNames.Text.Plain);
				plainBody.TransferEncoding = Tools.IsSevenBit(plainBody.ContentStream)
				                             	? TransferEncoding.SevenBit
				                             	: TextTransferEncoding != TransferEncoding.SevenBit
				                             	  	? TextTransferEncoding
				                             	  	: TransferEncoding.QuotedPrintable;
				plainBody.ContentType.CharSet = CharacterEncoding.HeaderName; // RFC 2045 Section 5.1 - http://www.ietf.org
				return plainBody;
			}
		}

		/// <summary>
		/// Get the text representation of the source document
		/// </summary>
		public override string DocText
		{
			get { return _plainText; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions