launch the default mail client, such as Outlook or Outlook Express

ivan74

Newcomer
Joined
May 16, 2005
Messages
21
Hi
I have win application wich will run on approximately 200 computers, mostly win xp, but probably there will be some win 98 as well.
I want to start a defalut email client (I suppose it will be outlook express on 90% of computers, but I can't be sure) on that machine with new message dialog opened and "to", "subject" and "attachements" properties filled.
So far I have only found exapmles on how to send mail through outlook or smtp client. Please help
 
I've found this peace of code
Code:
 Dim psi As New ProcessStartInfo
 psi.UseShellExecute = True
        psi.FileName = _
             "mailto:" & System.Web.HttpUtility.UrlEncode("someone@somewhere") & _
             "?subject=" & System.Web.HttpUtility.UrlEncode("test") & _
             "&body=" & System.Web.HttpUtility.UrlEncode("test")
But what I can't figure out is how to set up attachment? That is why I need this feature anyway.
I just found out that there is NO attachment atribute.
I can't trust that client will send back to me right files.
Is there any way to launch default mail client and put some files in the attachments list?
 
Last edited:
Ivan74

Althought I have not got a way of opening outlook and filling in the to, from, attachments etc. I do have two other ways of sending email with attachments.

The first is to use the smtp client and send it direct, but you then have to keep a record of emails sent for yourself.

The other has been using Outlook, this sends the email and saves it in the sent items folder. What I have not been able to do is test it with Outlook Express, the one machine that is using Outlook Express here also has outlook installed, the program saved the email to Outlooks outbox and would not let Outlook Express see it. So not sure if it would just crash on a machine with only Outlook Express on it, there may be a setting that tells it which version to use that I have not found yet.

Anyway if these are of any help then let me know and I will post the code.
 
I think what Pendragon is trying to tell you is, 'use the MAPI objects'. Using the MAPI controls you can send attachements or whatever you want through Visual Basic. On most computers that means it will load Outlook Express. However on some PCs if some other MAPI compatible email program is set to default, it will be loaded instead.

I have used this strategy in many programs in Visual Basic.
 
Hi
I can start Outlook like this:
Code:
Dim olApp As Outlook.Application
        Dim olNS As Outlook.NameSpace
        Dim olMessage As Outlook.MailItem

        olApp = CreateObject("Outlook.Application")
        olNS = olApp.GetNamespace("MAPI")



        olMessage = olApp.CreateItem(Outlook.OlItemType.olMailItem)
        olMessage.To = "someone@somewhere.com"
        olMessage.Subject = "test"
        olMessage.Body = "hi"

        olMessage.Send()

        olApp.Quit()
But then it starts only Outlook, never Outlook express. Unless I am missing something. (I am guessing that most of my clients will not have Outlook.)

Also I can send mail like this:
Code:
        Dim mes As New System.Web.mail.MailMessage
        mes.To = "someone@somewhere.com"
        mes.Body = "test"

        Dim att As New System.Web.Mail.MailAttachment("c:\file.txt")
        mes.Attachments.Add(att)
        
       mes.From = "me@here.com"

        System.Web.Mail.SmtpMail.SmtpServer = "smtp.here.com"
        MessageBox.Show(System.Web.Mail.SmtpMail.SmtpServer)

        System.Web.Mail.SmtpMail.Send(mes)
The problem here is that at design time I don't know two things:
mes.From and System.Web.Mail.SmtpMail.SmtpServer.

Is there any other way, or am I missing something?
 
Don't know if this will help, but this is from an app I wrote in VB6. It will use the default email client. This is part of a Corrective Action System program for internal use in our company.

Code:
On Local Error GoTo MAPI_Error
MAPISession.SignOn  ' sign onto MAPI email session
MAPIMessages.SessionID = MAPISession.SessionID  ' link messages to session
                    
With MAPIMessages
.MsgIndex = -1
.Compose    ' compose a new email
' send to Originator
.RecipIndex = 0
.RecipDisplayName = UserInfo(1, cboOriginator.ListIndex)
.RecipType = mapToList
' send to Assignee
.RecipIndex = 1
.RecipDisplayName = UserInfo(1, cboAssign_To.ListIndex)
.RecipType = mapToList
.MsgSubject = "Subject Here"
.MsgNoteText = "Text Here"
.Send True  ' show the message
End With

MAPISession.SignOff ' sign off MAPI email session
MAPISession.Password = ""   ' clear out password for security purposes
On Local Error GoTo 0

Todd
 
Thank you for your reply.
I've found lots of similar examples on the net for vb6, but it seems that there is no mapisession or mapimessages classes in .NET. And when I looked for MAPI in MSDN I didn't get much.
Still I am in a dark.
 
Back
Top