Emailing with default client

  • Thread starter Thread starter Dustin Davis
  • Start date Start date
D

Dustin Davis

(using VB.NET 2005)

I'm writing a desktop application that I would like to have the ability
to email files. I've set up the SMTP portion, now I would like to have a
MAPI option.

I found a MAPI tutorial, but it does a bit more than I want it to. What
I would like to do is this:

1. Open the default mail client's compose window.
2. Add an attachment

Then the user can fill out the To: Subject: etc.

Can anyone help me with this?

Thanks,
Dustin
 
Dustin,

Your problem is in this sentence
2. Add an attachment

Not all emailclients have the possiblitity to add attachments. It is as well
not in the standard code for opening default email clients.

This question is thousand times done in this newsgroup. If you know that it
is Office Outlook than there are possibilites and I have read from Carlos
that it can as well at OutlookExpress, but not right from the box.

Cor
 
Carlos,

That is systemwebmail. A default client is opened in this way.
\\\
///a reference to System.Web
///using System.Web;
///using System.Diagnostic
Process.Start ("mailto:" + HttpUtility.UrlEncode("(e-mail address removed)")
+ "?subject=Does this helps" + "&body=How do you do?");
///

Cor
 
I've tried the mailto: method, but I can't seem to add an attachment.
I'm watching another program do the very thing I am trying to do, but I
don't know how it is doing it. It opens the default mail client compose
window with the specified file attached. Amazingly it works when I have
either Outlook Express or Thuderbird as my default mail client.

I've tried using the VB6 MAPI controls (MAPISession & MAPIMessages), I
can sent through Outlook Express, but not Thunderbird. When I send
through Outlook express it makes me enter my password twice - the fist
time is when it connects (it then wants to download all my new
messages), then again when I got to send. Frustrating :(
 
Ah, yes, but anyway an approach would be to use SystemWebMail and provide
your own compose form with subject, destination textboxes and attach button
since I don´t think that Simple MAPI will be able to add attachments, so
either you need to use Extended MAPI (C++), not .NET compatible, or use CDO,
which may not work for all e-mail clients.

See:

Differences between CDO, Simple MAPI, and Extended MAPI
http://support.microsoft.com/kb/200018/en-us


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
So, in any case, I got it to work as I needed using the VB6 MAPI
controls. Without going into too much detail, I'll just post the
function here in case anyone else is interested. Let me know if you have
question on what I did here (This works in Mozilla Thunderbird and
Outlook Express):

Private Function SendMapiEmail() As Boolean
Dim FilePaths() As String = IO.Directory.GetFiles(Me.TempOutputPath)

Try
With Me.MapiSession
If .SessionID = 0 Then
.DownLoadMail = False
.LogonUI = True
.SignOn()
End If
End With

With Me.MapiMessages
.SessionID = Me.MapiSession.SessionID
.Compose()
.MsgSubject = "Images Attached"
.MsgNoteText = "(See Attached)"
For i As Integer = 0 To FilePaths.Length - 1
.AttachmentIndex = i
.AttachmentPathName = FilePaths(i)
Next
.Send(True)
End With
Me.MapiSession.SignOff()
Catch ex As Exception
MsgBox("Error sending MAPI email: " & ex.Message,
MsgBoxStyle.Exclamation, AppName)
Return False
End Try

Return True
End Function
 
So the MAPI controls allow to send attachments. Did you investigate of the
Simple MAPI allow that? They are 12 API functions or so and if it works it
would allow you to get rid of the VB6 controls in your app...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
Here's the steps you should follow to get the code to work that I posted
previously:

1. Add a reference to the COM "Microsoft MAPI Controls 6.0"
2. In your Toolbox, right-click and select "Choose items..."
3. In the COM Components tab, select the "Microsoft MAPI Messages
Control" and the "Microsoft MAPI Session Control"
4. Add the controls to your form
 
I don't have VB6 installed on my computer and don't want to install it
really. Can I get the controls and just add them to the bin directory? If
so, where can I find them>
 
I'm not sure. I don't have vb6 installed either. VB.NET 2005 is the only
version I have ever installed on my machine.
 
Back
Top