Last post Feb 05, 2014 08:26 PM by Paul Linton
Feb 04, 2014 10:06 PM|compuluv|LINK
I am wrote some code to send an email using smtp and it works fine but I want to be able to display the email (it will use outlook by default for most of my users) before it gets sent. I want to do this to be able to add data as necessary or fix errors.
I could accomplish this using the outlook interop but because of some server issues I am unable to use that. Here is the code I am using:
var attachment = new Attachment(@"\\Admin\UserX\TestProj\Daily\summary.xlsx");
var mail = new MailMessage("Testers@test.com", "Testers@test.com");
var client = new SmtpClient
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = "smtp.google.com" //not sure if this is right just using for example purposes
mail.Subject = "Spreadsheet " + DateTime.Now.ToString("MM-dd-yyyy");
mail.Body = "Hello Everyone," + "\n" + "\n" + "Attached is the Spreadsheet for your review." + "\n" + "\n" + "Thank you!" + "\n" + "\n";
Please let me know what how to display the email before being sent.
Feb 04, 2014 11:50 PM|Sanjay.Baroda|LINK
If you are working on Desktop application then you can make use of MAPI to send e-mail using default email client.
http://www.codeproject.com/Articles/17561/Programmatically-adding-attachments-to-emails-in-C for more detail about how to send e-mail using default email client with attachment.
i.e. Calling SendMailPopup will display the email client send mail dialog and you can then add further recipients or attachments and hit the send button manually.
Feb 05, 2014 06:30 AM|compuluv|LINK
Hi Sanjay, wasn't really specific in my post. I am using .Net to go about this.
Feb 05, 2014 08:26 PM|Paul Linton|LINK
"I could accomplish this using the outlook interop"
??? How? Your C# code runs on the server not on the client. Most Servers would not have Outlook installed. Even if they did you would be operating under the account of the web server process not the client. If you were operating under the clients account
then any windows displayed by Outlook would be on the Server. There are so many reasons that this could not work.
What you could do is provide a text box that you display on a page. The text box would be initialized with the default message and your client could modify the message. When they submit you then create an SMTP message using the contents of the text box
as the body.