问题
I\'m looking for a way to open a New mail in Outlook window.
I need programically fill: from, to, subject, body information, but leave this new mail window open so user can verify content / add something then send as normal Outlook msg.
Found that:
Process.Start(String.Format(
\"mailto:{0}?subject={1}&cc={2}&bcc={3}&body={4}\",
address, subject, cc, bcc, body))
But there is no \"From\" option (my users have more than one mailbox...)
Any advice(s) ?
回答1:
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 );
回答2:
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());
}
}
}
回答3:
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.
来源:https://stackoverflow.com/questions/6148639/how-to-open-outlook-new-mail-window-c-sharp