How do I popup the compose / create mail dialog using the user's default email client?

前端 未结 7 1733
攒了一身酷
攒了一身酷 2021-01-05 15:32

The use case is simple. At a certain point of time, I need to be able to show the user his familiar compose email dialog (Outlook or other) with

  • fields like f
7条回答
  •  庸人自扰
    2021-01-05 16:05

    you can use a trick if you intend to use Outlook[this code is based on outlook 2010[v14.0.0.]] Create Outlook MailItem and transmit file (ie download) if user opens the file (.msg) the compose message dialog opens automatically

    here is the code ...

        Microsoft.Office.Interop.Outlook.Application outapp = new Application();
        try
        {
    
            _NameSpace np = outapp.GetNamespace("MAPI");
            MailItem oMsg = (MailItem)outapp.CreateItem(OlItemType.olMailItem);
            oMsg.To = "a@b.com";
            oMsg.Subject = "Subject";
    
           //add detail
    
            oMsg.SaveAs("C:\\Doc.msg", OlSaveAsType.olMSGUnicode);//your path
            oMsg.Close(OlInspectorClose.olSave);
        }
        catch (System.Exception e)
        {
            status = false;
        }
        finally
        {
            outapp.Quit();
        }
    

    then transmit the file you created say "Doc.msg"

        string filename ="Doc.msg";//file name created previously
        path = "C:\\" + filename; //full path ; 
        Response.ContentType="application/outlook";
        Response.AppendHeader("Content-Disposition", "filename=\"" + filename + "\"");
        FileInfo fl = new FileInfo(path);
        Response.AddHeader("Content-Length", fl.Length.ToString());
        Response.TransmitFile(path,0,fl.Length);
        Response.End();
    

提交回复
热议问题