2
votes

I have a requirement to create a .Net application which will send a mail message (with attachments and possibly html formatting) but without using System.Net.Mail (we can't ask for user SMTP details) or Outlook (this is for PCs without Outlook installed).

I've been looking into MAPI today but it seems that it can only be implemented by creating a C/C++ library and then using a .NET wrapper which is a lot of work in an unfamiliar area. Most of the sample code and projects around are quite old too, and some rely on the SMTP server details anyway once you start poking around.

Is there a .net friendly solution to sending email without SMTP, Outlook, or delving into C++ and MAPI? Maybe a third party MAPI library?

3
Is the problem sending SMTP over the network? Because there is more than one way to use SMTP. See deliveryMethod msdn.microsoft.com/en-us/library/ms164240(v=vs.110).aspx - ta.speot.is
No the problem is that I have been told that I cannot ask the user to fill in any SMTP details. - Carl Onager
Have you considered Amazon Simple Mail Service? - Akash Kava

3 Answers

2
votes

I've found one way to do it that avoids all the pitfalls mentioned above but it's not brilliant. This article covers what is required but it appears to be a bit hit and miss depending on the setup of your system.

Basically you have to use the System.Runtime.InteropServices to decorate the various classes needed with a StructLayout attribute so that they are handled in memory correctly. This allows you to use the MAPI32.DLL SendMail function:

<DllImport("MAPI32.DLL")> _
Private Shared Function MAPISendMail(ByVal sess As IntPtr,
         ByVal hwnd As IntPtr, ByVal message As MapiMessage,
         ByVal flg As Integer, ByVal rsv As Integer) As Integer
End Function

I have developed some .NET code based on this which mostly works but there is a problem in that managed code is simply not compatible with MAPI in the long run which has led to this follow up question.

0
votes

you are conused smtp is http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol that is THE EMAIL protocol.

you MUST use a smtp server.

Send email using System.Net.Mail through gmail

0
votes

An SMTP or other mail server is a necessity if you want to send mails. That you redirect your mail message using an email application like Outlook which in turn talks to Exchange who finally delivers your message using SMTP does noet neglect the fact that SMTP is used in the end.

You want to do the impossible: you do not want to rely on an already installed mailing application (Outlook, Thunderbird), nor do you want to connect to a mail server: then you cannot send mail.

As for this part of your problem description:

we can't ask for user SMTP details

You can then perhaps write a webservice that you host, which is a layer over an SMTP or Exchange server under your control. You write this service to accept mail message from your applications, so clients can call it without knowing about the underlying transport or the server configuration; all they need to know is your service's address.

Your applications can then send a SendEmail() request to the service, without the need for configuring an SMTP server or Outlook connection at the client.