954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to send am Email using c# ?

Hi :)

I want to click on a button and open the mail
box so i can put message and send it, how
can i do that ?

Thanks.

1qaz2wsx7
Newbie Poster
17 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

If by mail box you mean an email application like outlook, you can use the Process class from System.Diagnostics.

System.Diagnostics.Process.Start( "outlook.exe" );
Hamrick
Posting Whiz
325 posts since Jun 2007
Reputation Points: 180
Solved Threads: 34
 

Hi :)

Thanks for the answer, but i want it to directly go
to a new message and automaticly insert an email
that i choose and let me write a message and send it.

How can i do that ?

Thanks.

1qaz2wsx7
Newbie Poster
17 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

I'm not sure you can do that with outlook, but I'd start by seeing if there's a command line switch I could use. Something like

System.Diagnostics.Process.Start( "outlook.exe /newmessage" );

You're probably asking too much for a simple solution and the best way to solve the problem would be to write your own mail handler instead of calling an existing one. :(

Hamrick
Posting Whiz
325 posts since Jun 2007
Reputation Points: 180
Solved Threads: 34
 

You might want to try the HTML mailto syntax.

For example: email me>

Clicking on the above link will open your default email handler with message already started in Body. (Check this page for more examples http://www.ianr.unl.edu/internet/mailto.html )

Now you have to see how to integrate HTML into your application.

Good luck.

zmariow
Junior Poster in Training
71 posts since Aug 2007
Reputation Points: 14
Solved Threads: 1
 

I give u a brief peace of code
First u must include
using System.Net.Mail;
//Initialize an SMTP client
SmtpClient objSmtpClient = new SmtpClient();
MailMessage objMail = new MailMessage();
// Precise the mail adress sender and reciever
MailAdress oSenderAdress = new MailAdress("dsd@dsdd.fd");
MailAdress oRecieverAdress = new MailAdress("sdsd@dsdsd.fd");
//Parameter the objMail
objMail.From = oSenderAdress;
objMail.To = oRecieverAdress;
//To send the email u can use the method
try{
objSmtpClient.send(objMail);
}
catch(Exception caught)
{ Response.Redirect("http://www.yourWebSite/ErrorPage.asp");
}

Jugortha
Junior Poster
172 posts since Oct 2007
Reputation Points: 11
Solved Threads: 16
 

I have actually seen what 1qaz2wsx7 is talking about. It's actually pretty cool. I first saw it at work when a end user needed some help. She was using a Access DB that on one of the forms would actually open up Lotus Notes and fill in the Recipient, Subject and Body.

On a windows machines it uses the default email program that I think can be set int Internet Options -> Programs-> Email setting.

My 2 Cents

blacklocist
Junior Poster in Training
87 posts since Apr 2006
Reputation Points: 10
Solved Threads: 2
 

WOw this is an old thread, but it is possible to launch the default email program with a new message window wih this code:

System.Diagnostics.Process.Start("mailto:foo@bar.info");

the when Windows sees the mailto protocol it opens the associated program. The program will open a new message page only (Well that's what Windows Mail and Outlook did on my Vista system). You can change the mailto arguments. See: http://www.ianr.unl.edu/internet/mailto.html

scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
 

you can use the mailto: syntax to fill in the email in its entirety. It's throughly documented in the RFC822 standard...

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

Hi :)

I want to click on a button and open the mail box so i can put message and send it, how can i do that ?

Thanks.

hi
hw r u? i m fine well. im studying here.what r u doing?

gareeb
Newbie Poster
1 post since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Please use the following code.
and add .dll's
Interop.Outlook.dll
Interop.Microsoft.Office.Core.dll
Office.dll
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem objMail;
objMail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
objMail.To = "s731061@emirates.com;
objMail.Subject = "Testmail";
objMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
objMail.Body = "Welcome to Outlook";
objMail.Display(Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML);
}
sabeer pasha.

sabeerpasha
Newbie Poster
3 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 
Please use the following code. and add .dll's Interop.Outlook.dll Interop.Microsoft.Office.Core.dll Office.dll protected void Button1_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem objMail; objMail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); objMail.To = "s731061@emirates.com; objMail.Subject = "Testmail"; objMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; objMail.Body = "Welcome to Outlook"; objMail.Display(Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML); } sabeer pasha.


Thanks SabeerPasha, it worked for me.

Seema
Newbie Poster
1 post since May 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You