Thursday, February 7, 2008

c#: to send the email in html format

using System;
using System.Net.Mail;
using System.Net.Mime;
using System.Drawing;

namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{

SendMail();

Console.Read();
}

//program to send mail
public static void SendMail()
{
/******* IMAGE FOR EMAIL *********/

Image EmailLogo = RnDConsoleCSharp.Resources.mylogo;

byte[] commentImg;

using (System.IO.MemoryStream stream = new System.IO.MemoryStream())

{

EmailLogo.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg );

commentImg = stream.ToArray();

}

/**********************************/



try

{

MailAddress from = new MailAddress("rupeshn@mindfiresolutions.com");

MailAddress to = new MailAddress("logintoabhi@hotmail.com");

MailMessage message = new MailMessage(from, to);

message.IsBodyHtml =true;

message.Subject ="TEST with image";


string bodyText = "
Staff Name:\" + staffName + \"
Staff Query:\" + queryText + \"
";

message.Body = bodyText;

SmtpClient client = new SmtpClient("NETSERVER");

client.Send(message);

}

catch (Exception ex)

{

Console.WriteLine("E-Mail Failed\n\n" + ex, "Email");

}


}


}
}

No comments:

About Me

He is working in an indian firm as a s/w engineer.During his work in the company he got many opportunities to deal with. He has experience on high-end techonologies like ASP, VB 6.0, MS.Net 2005, WMS, Python, Ajax, Ruby on Rails etc. He likes to work on client-server systems, remoting, web services, windows services etc. He loves to create utilities that makes his work easier and faster.