How can I make SmtpMail.Send bring up Outlook email client?

E

Ed Sutton

How can I show the email client UI so the user can send the attachment
to the desired recipient. I get an exception if I leave the
MailMessage.To property blank. Is there any way to do this?

I found a Microsoft example that uses mapi32.dll that can do this. But
I can nopt make the SmtpMail work like I want.

Thanks in advance,

-Ed


Using System.Web.Mail;

MailMessage mailMsg = new System.Web.Mail.MailMessage();
mailMsg.To = "(e-mail address removed)"; // Throws exception if left blank
mailMsg.From = "(e-mail address removed)";
mailMsg.Subject = "Hello";
mailMsg.Body = "My body";
mailMsg.Attachments.Add(new MailAttachment(fileAttachment));
SmtpMail.Send(mailMsg);
 
G

Guest

From memory you might have to use the mailto syntax and start a process using the system.process namespace. I do not know if there has been a post here, but in the vbdotnet groups there have been several posts. Do a search for 'mailto' it should give you an answer.
 
G

Guest

Found the Answer about 3 days ago in this group.

==================================================
This is the easy way :

using System.Diagnostics;

string toEmail = "(e-mail address removed)";
string subject = "Love the Program";
string body = "Thanks a lot";
string message = string.Format( "mailto:{0}?subject={1}&body={2}", toEmail,
subject, body );

Process.Start( message );

Add this to a linklabel and bobs your uncle.

Example app can be found at
http://www.publicjoe.f9.co.uk/csharp/snip/snip007.html


Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html

====================================================
 
E

Ed Sutton

Thank you for your reply.

I need to add multiple attachments as well. I do not see how I can do
this with this approach.

I guess I must stick with the "Simple MAPI" Microsoft example that uses
mapi32.dll. It works fine but takes a lot more code. I was hoping to
use the SmtpMail.Send built-in to System.Web.Mail but I can not get it
to launch the default email client.

Thank you for your suggestion,

-Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top