tags:

views:

314

answers:

3

I am currently using Process.Start to send simple emails from my WinForms app. Can you think of any way to add a file attachment to the email? (Edit: using Process.Start?)

Here's what I use now:

Process.Start("mailto:[email protected]?subject=" + HttpUtility.HtmlAttributeEncode("Application error report") + "&body=" + body);
+3  A: 

Try something like this -->

MailMessage theMailMessage = new MailMessage("[email protected]", "[email protected]");
theMailMessage.Body = "body email message here";
theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment"));
theMailMessage.Subject = "Subject here";

SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp");
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential("[email protected]", "password");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

Alright, based on your edit and additional info, I found this Blog Post by Jon Galloway, "Sending files via the default e-mail client".

This looks like what you may be looking for, though I don't profess any knowledge with this way as I have always used the method I posted.

Hopefully it is of use to you.

Refracted Paladin
Important question I forgot to ask. How do you want to send it? Outlook, Google, ect....
Refracted Paladin
short, sharp. Sweet! +1
Mitch Wheat
+1 That will teach me for spending time seeing if this was even possible using Process.Start :) Turns out that you can't add attachments that way, so the already correct System.Net.Mail becomes an even better answer.
David Hall
What's funny, is if you search my old posts on SO, I posted an almost identical question almost a year ago. I guess this is me giving back! I love SO!
Refracted Paladin
The user's default email client opens and presents the message ready to send. I have avoided using SmtpClient thus far because I didn't want to turn my program into an email client. It may be a support issue for the user to find and edit in their email host name. I was hoping someone knew a trick for Process.Start... I should have made this more clear.
P a u l
MAPISendMail seems to work with win7-64 and Thunderbird which is the only email client I have for testing. The wrapper class code is linked to in the Galloway article. I guess a lot of users won't even be using a local email client nowadays (gmail) so don't know what I will do about that.
P a u l
A: 

Please see: SmtpClient Class

Mitch Wheat
A: 

this code is not working properly please guide me some more your thankfully shaukat ali abbasi web developer dataslices karachi, pakistan

shaukat ali abbasi