Surendra Sharma

Surendra Sharma

Search This Blog

Friday, February 21, 2014

How to check email content generated by SMTPClient class in C#


Sometimes we want to check that what is the email content generated by SMTPClient class in C#.
Use below code for it

            SmtpClient client = new SmtpClient("localhost", 25);
            client.PickupDirectoryLocation = @"D:\TestApp\";
            client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
            client.Send("a@a.com", "b@b.com", "test subject", "this is body");

It should keep mail file having name like “f73517fb-fac9-473e-966a-7d46659318f8.eml” in D:\TestApp folder.

Its content is something like below
X-Sender: a@a.com
X-Receiver: b@b.com
MIME-Version: 1.0
From: a@a.com
To: b@b.com
Date: 21 Feb 2014 19:38:44 +0530
Subject: test subject
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

this is body


Please leave your comments or share this tip if it’s useful for you.

No comments:

Post a Comment