compose email in outlook with attachment

2019-02-20 19:51发布

问题:

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)