How to Open Outlook New Mail Window C#

How to open Outlook new mail window c#

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 );

C# open outlook mail window

I tried to use Microsoft.Office.Interop.Outlook but I get an error

You need to add a COM reference to the project. Right click on the dependencies of your project and choose Add COM references:

COM references VS2022

In the dialog window you can find the entry for Outlook and select it.

Outlook COM reference

Viola! Click the Ok button and use the OOM in your code.

How to open Outlook's new mail window with prepopulated attachment

Old question, but I also ran in to this so here's a copy and paste solution:

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

oMsg.Subject = "subject something";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "text body"; //Here comes your body;
oMsg.Attachments.Add("c:/temp/test.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
oMsg.Display(false); //In order to display it in modal inspector change the argument to true

You'll need to add a reference to the Microsoft.Office.Interop.Outlook component in your project.

Opening a new Outlook 2016 window with c#

It doesn't matter which Office interop files are used (to which Office version they belong) - you can still automate Office applications from .Net applications. So, just add a COM reference (for Microsoft Office Outlook) to your application and use the following code:

using System;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace FileOrganizer
{
class Program
{
private void CreateMailItem()
{
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "This is the subject";
mailItem.To = "someone@example.com";
mailItem.Body = "This is the message.";
mailItem.Display(false);
}
}
}

To open outlook new email window with content already filled

I think you do not need ASP.NET for this. All you need is mailto with the right parameters.

Example: 

<a href="mailto:someone@example.com?Subject=Hello%20again&body=This%20is%20body">
Send Mail</a>

This will send email to someone@example.com with subject "Hello" and body "This is body". You can also use CC parameter to add CC emails.

More info on this link

A related question that may help How do I properly encode a mailto link?

VS C# Button with Mailto function - it needs to open Outlook's new mail window

You can use hyperlink to open the default email client from website.

<a class='button' href='mailto:mailto:someone@test.com?subject={0}'>Email</a>

To display a hyperlink as button you can CSS like below:

.button {  font: bold 11px Arial;  text-decoration: none;  background-color: #EEEEEE;  color: #333333;  padding: 2px 6px 2px 6px;  border-top: 1px solid #CCCCCC;  border-right: 1px solid #333333;  border-bottom: 1px solid #333333;  border-left: 1px solid #CCCCCC;}
<a class='button' href='mailto:mailto:someone@test.com?subject={0}'>Email</a>


Related Topics



Leave a reply



Submit