How to send email using default email client?

前端 未结 4 1238
鱼传尺愫
鱼传尺愫 2020-11-30 08:04

I want to send an email from a .net windows forms application using the system\'s default email client (thunderbird, outlook, etc.). I\'d like to preset the subject and body

4条回答
  •  無奈伤痛
    2020-11-30 08:19

    If you are working in a MS Windows environment only then you can use MAPI32.DLL. A managed wrapper can be found here:

    http://www.codeproject.com/KB/IP/SendFileToNET.aspx

    Code looks like this:

    MAPI mapi = new MAPI();
    mapi.AddAttachment("c:\\temp\\file1.txt");
    mapi.AddAttachment("c:\\temp\\file2.txt");
    mapi.AddRecipientTo("person1@somewhere.com");
    mapi.AddRecipientTo("person2@somewhere.com");
    mapi.SendMailPopup("testing", "body text");
    
    // Or if you want try and do a direct send without displaying the mail dialog
    // mapi.SendMailDirect("testing", "body text");
    

提交回复
热议问题