compose email in outlook with attachment

孤者浪人 提交于 2019-12-01 12:31:12

问题


In my application, I have a requirement where if a user clicks on invoice number the generated invoice statesment is attached to a composed email in outlook. Using code below i am able to send automated emails but i need to just compose and open the outlook window for user to review and edit the contents. Do not send. Kindly help.

public void pdfStatement(string InvoiceNumber)

 {

     InvoiceNumber = InvoiceNumber.Trim();
     string mailServer = "server";
     string fileName = InvoiceNumber;
     string filePath = Server.MapPath("~/Content/reports/");
     string messageBody = "Its an automated test email, please ignore if you receive this.";
     CreateMessageWithAttachment(mailServer, filePath, fileName, messageBody);
 }


  public void CreateMessageWithAttachment(string mailServer, string filePath, string fileName, string messageBody)

      {

     MailMessage message = new MailMessage (
                                            "user@domain.com",
                                            "user@domain.com",
                                            "TestEmail",
                                             messageBody);

      filePath = filePath + fileName + ".pdf";

     // Create  the file attachment for this e-mail message.
     Attachment attach = new Attachment(filePath);
     attach.Name = fileName + ".pdf";
     // Add the file attachment to this e-mail message.
     message.Attachments.Add(attach);
     //Send the message. 
    SmtpClient client = new SmtpClient(mailServer);
     var AuthenticationDetails = new NetworkCredential("user", "password");
     client.Credentials = AuthenticationDetails;
     client.Send(message);
 }  

回答1:


not sure if this will help but how about u just create a form in tha page and allow user to type/see what they be sending. Sample here

Also Preview button can help

EDIT: Then u need to use Microsoft.Office.Interop.Outlook namespace to create a mail item.
First sample here
From the sample, the MailItem class(oMsg) also has a Display() Method which should display the created email.
Second sample (ASP.NET version)



来源:https://stackoverflow.com/questions/8449641/compose-email-in-outlook-with-attachment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!