Create an email message in .NET.

I want to create an email with an attachment, but not send it. Email should open in Outlook, where the user can send himself.

I played with the Mailto: command to open a new mail message, however the Outlook client does not seem to support adding attachments using the Mailto: command.

I do not want to use COM for this.

Does anyone know how to achieve this? I think this may not be possible without COM.

+3
source share
7 answers

, COM ( VSTO), - Outlook. Process.Start, Outlook , (VonC):

:

    outlook.exe /c ipm.note

:

    outlook.exe /c ipm.note /m someone@example.com

:

    outlook.exe /c ipm.note /a filename

:

    outlook.exe /c ipm.note /m someone@example.com&subject=test%20subject&body=test%20body

Outlook :

Outlook 2007:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Outlook\InstallRoot

Outlook 2003:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Outlook\InstallRoot

Outlook XP:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Outlook\InstallRoot
+4

Outlook, , COM. - , Outlook, SMTP System.Net.Mail?

: , , mailto, . :

mailto:foo@bar.com?subject=foo&body=bar&attachment="C:/foo/bar.txt"

Outlook? , - COM , , Outlook .

+5

- COM ( interop), SMTP ( )

+1

, Outlook ( , MAPI), System.Net.Mail .

0

smtp

<system.net>
<mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="c:\pickup-smtp\"/>        
  </smtp>
</mailSettings>

0

:

using Microsoft.Office.Interop.Outlook;

private void CreateMailItem()
{
    Outlook.MailItem mailItem = (Outlook.MailItem)
        this.CreateItem(Outlook.OlItemType.olMailItem);
    mailItem.Subject = "This is the subject";
    mailItem.To = Environment.UserName + "@example.com";
    mailItem.Body = "This is the message.";
    mailItem.Importance = Outlook.OlImportance.olImportanceLow;
    mailItem.Display(false);
}
0

.net , . . . .

0
source

Source: https://habr.com/ru/post/1708188/


All Articles