How to open Outlook new mail window c#

前端 未结 3 2162
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 02:05

I\'m looking for a way to open a New mail in Outlook window.

I need programically fill: from, to, subject, body information, bu

相关标签:
3条回答
  • 2020-11-29 02:23

    I've finally resolved the issue. Here is piece of code resolving my problem (using Outlook interops)

    Outlook.Application oApp    = new Outlook.Application ();
    Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem ( Outlook.OlItemType.olMailItem );
    oMailItem.To    = address;
    // body, bcc etc...
    oMailItem.Display ( true );
    
    0 讨论(0)
  • 2020-11-29 02:35

    You can't do this with mailto. Either your client will have to select the account they are sending from, which defaults to their default account or you will have to provide a mail form and set the headers when you send the e-mail.

    0 讨论(0)
  • 2020-11-29 02:46

    Here is what i have tried. It's working as expected.

    This application Adding Recipients, adding cc and adding subject and opening a new mail window.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Threading;
    using Outlook = Microsoft.Office.Interop.Outlook;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void ButtonSendMail_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> lstAllRecipients = new List<string>();
                //Below is hardcoded - can be replaced with db data
                lstAllRecipients.Add("sanjeev.kumar@testmail.com");
                lstAllRecipients.Add("chandan.kumarpanda@testmail.com");
    
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector oInspector = oMailItem.GetInspector;
               // Thread.Sleep(10000);
    
                // Recipient
                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
                foreach (String recipient in lstAllRecipients)
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
                    oRecip.Resolve();
                }
    
                //Add CC
                Outlook.Recipient oCCRecip = oRecips.Add("THIYAGARAJAN.DURAIRAJAN@testmail.com");
                oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                oCCRecip.Resolve();
    
                //Add Subject
                oMailItem.Subject = "Test Mail";
    
                // body, bcc etc...
    
                //Display the mailbox
                oMailItem.Display(true);
            }
            catch (Exception objEx)
            {
                Response.Write(objEx.ToString());
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题