launch default email client with a new message 
Author Message
 launch default email client with a new message

Anyone have a code example of how to launch the systems default email client
with a new message while setting the to, subject, and message body?

thanks
Paul



Sun, 30 Oct 2005 02:23:54 GMT  
 launch default email client with a new message
Hello,


Quote:
> Anyone have a code example of how to launch the systems
> default email client with a new message while setting the to,
> subject, and message body?

\\\
Private Sub SendMail( _
    ByVal strAddress As String, _
    ByVal strSubject As String, _
    ByVal strBody As String, _
    Optional ByVal strCC As String = "", _
    Optional ByVal strBCC As String = "", _
    Optional ByVal blnHTML As Boolean = False _
)
    Dim s As String
    s = "mailto:" & strAddress & "?subject=" & strSubject
    If Len(strCC) > 0 Then
        s = s & "&cc=" & strCC
    End If
    If Len(strBCC) > 0 Then
        s = s & "&bcc=" & strBCC
    End If
    s = s & "&body="
    If blnHTML Then
        s = s & "<html>"
    End If
    s = s & strBody
    If blnHTML Then
        s = s & "</html>"
    End If
    Process.Start(s)
End Sub

Private Sub Test()
    SendMail( _

        "Foo or Bar", _
        "The body", _


    )
End Sub
///

Regards,
Herfried K. Wagner



Sun, 30 Oct 2005 02:41:47 GMT  
 launch default email client with a new message
Thanks Herfried,

This is amazing!  I saw the statement: "Process.Start(s)" and I thought "he
left something out...".  Just to avoid making myself look foolish, I figured
I'd better try the code first.  Okay, it worked!!!!

It seems to be in System.Diagnostics.  But how does it know what process?
Does it infer this from the "mailto:"?  Where is this wondrous thing
documented?

Where is Process defined?


Quote:
> Hello,


> > Anyone have a code example of how to launch the systems
> > default email client with a new message while setting the to,
> > subject, and message body?

> \\\
> Private Sub SendMail( _
>     ByVal strAddress As String, _
>     ByVal strSubject As String, _
>     ByVal strBody As String, _
>     Optional ByVal strCC As String = "", _
>     Optional ByVal strBCC As String = "", _
>     Optional ByVal blnHTML As Boolean = False _
> )
>     Dim s As String
>     s = "mailto:" & strAddress & "?subject=" & strSubject
>     If Len(strCC) > 0 Then
>         s = s & "&cc=" & strCC
>     End If
>     If Len(strBCC) > 0 Then
>         s = s & "&bcc=" & strBCC
>     End If
>     s = s & "&body="
>     If blnHTML Then
>         s = s & "<html>"
>     End If
>     s = s & strBody
>     If blnHTML Then
>         s = s & "</html>"
>     End If
>     Process.Start(s)
> End Sub

> Private Sub Test()
>     SendMail( _

>         "Foo or Bar", _
>         "The body", _


>     )
> End Sub
> ///

> Regards,
> Herfried K. Wagner



Sun, 30 Oct 2005 12:37:48 GMT  
 launch default email client with a new message


Quote:
>It seems to be in System.Diagnostics.  But how does it know what process?
>Does it infer this from the "mailto:"?

The "mailto:" is indeed the thing that does the magic.  Anything you
send to Process.Start is interpreted by the Windows Desktop Explorer,
and when Explorer sees a "mailto:" tag it does the same thing as any
web browser: launch the default e-mail client.

Quote:
>Where is this wondrous thing documented?

I don't recall ever seeing official documentation but it works...

Process.Start also launches the default application for a document
type if you just specify a document name, e.g. "letter.doc".

You can test what it does by starting a command prompt and typing
"start ", followed by the argument you would supply to Process.Start.
Works exactly the same way.

start mailto:Foozle -- starts default e-mail client w/mail to Foozle

start readme.rtf -- starts default word processor with readme.rtf (but
Windows first checks that the file exists)

Cool, huh? ;-)  Very useful in batch files...

Quote:
>Where is Process defined?

It's a class in System.Diagnostics, as you wrote above.

What you can't do with the "mailto:" trick is attach files.  The most
compatible way to do this is the old Simple MAPI interface that you
have to use through interoperation. My Toolbox library interfaces some
Simple MAPI functions: http://www.kynosarges.de/Toolbox.html
Source code included, copy freely whatever you can use.
--
http://www.kynosarges.de



Sun, 30 Oct 2005 15:04:12 GMT  
 launch default email client with a new message

says...

Quote:
> Anyone have a code example of how to launch the systems default email client
> with a new message while setting the to, subject, and message body?

behind a button for example:
1)
sendmail.Send( _


        "The subject", _
        "The Body", _
        "Optional smtpserver else localserver will be used", _
        "Optional CC", _
        "Optional BCC", _
        "Optional c:\temp\Attachment", _
        "Optional Priority normal,low,high", _
        Optional Post in HTML? 1 or 0)

2)
reference your project to the system.web

3)
create a module with:
Imports System.Web.Mail
Module sendmail
Function Send(ByVal strFROM As String, ByVal strTO As String, ByVal
        strSUBJECT As String, ByVal strBODY As String, Optional ByVal
        strSMTPSERVER As String = "localhost", Optional ByVal strCC As
        String = "", Optional ByVal strBCC As String = "", Optional ByVal
        strATTACHMENT As String = "", Optional ByVal strPRIORITY As String
        = "Normal", Optional ByVal strHTMLPOST As Boolean = False)

        Dim email As New MailMessage()
        Dim smtpserver As SmtpMail

        'REQUIERD ITEMS FOR SENDING
        email.From = strFROM        'From Address
        email.To = strTO            'To Address
        email.Subject = strSUBJECT  'Subject
        email.Body = strBODY        'Body text as string

        'Optional ITEMS FOR SENDING
        smtpserver.SmtpServer = strSMTPSERVER 'This is your mail server
        email.Cc = strCC            'Send a Carbon-Copy (OPTIONAL)
        email.Bcc = strBCC          'Send a Blind Carbon-Copy (OPTIONAL)

        'email-attachment
        If strATTACHMENT <> "" Then
            Try
             email.Attachments.Add(New System.Web.Mail.MailAttachment _
                                        (strATTACHMENT))
            Catch x As Exception
                MsgBox(x.Message.ToString) 'Return the error to the user
            End Try
        End If

        'mail priority
        Select Case UCase(strPRIORITY)
            Case "LOW"
                email.Priority = MailPriority.Low
            Case "NORMAL"
                email.Priority = MailPriority.Normal
            Case "HIGH"
                email.Priority = MailPriority.High
            Case Else
                email.Priority = MailPriority.Normal
        End Select

        'Post as type:
        If (strHTMLPOST) Then
            email.BodyFormat = MailFormat.Html
        Else
            email.BodyFormat = MailFormat.Text
        End If

        MsgBox("sending:" & _
                email.From & Chr(13) & _
                email.To & Chr(13) & _
                email.Subject & Chr(13) & _
                email.Body & Chr(13) & _
                email.Priority & Chr(13) & _
                smtpserver.SmtpServer)
        'Sending the mail
        Try
            smtpserver.Send(email)
        Catch x As Exception
            MsgBox(x.Message.ToString) 'Return the error to the user
        End Try
        'clearing all
        email = Nothing
        smtpserver = Nothing
    End Function
End Module

regards git



Sun, 30 Oct 2005 21:47:04 GMT  
 launch default email client with a new message
Thanks Chris,

Thanks for taking the time to provide such a complete answer.  I love
newsgroups like this, and it people like you that make them great.  I'm just
now looking at your website and toolbox, and it looks terrific too.

Phil


Quote:


> >It seems to be in System.Diagnostics.  But how does it know what process?
> >Does it infer this from the "mailto:"?

> The "mailto:" is indeed the thing that does the magic.  Anything you
> send to Process.Start is interpreted by the Windows Desktop Explorer,
> and when Explorer sees a "mailto:" tag it does the same thing as any
> web browser: launch the default e-mail client.

> >Where is this wondrous thing documented?

> I don't recall ever seeing official documentation but it works...

> Process.Start also launches the default application for a document
> type if you just specify a document name, e.g. "letter.doc".

> You can test what it does by starting a command prompt and typing
> "start ", followed by the argument you would supply to Process.Start.
> Works exactly the same way.

> start mailto:Foozle -- starts default e-mail client w/mail to Foozle

> start readme.rtf -- starts default word processor with readme.rtf (but
> Windows first checks that the file exists)

> Cool, huh? ;-)  Very useful in batch files...

> >Where is Process defined?

> It's a class in System.Diagnostics, as you wrote above.

> What you can't do with the "mailto:" trick is attach files.  The most
> compatible way to do this is the old Simple MAPI interface that you
> have to use through interoperation. My Toolbox library interfaces some
> Simple MAPI functions: http://www.kynosarges.de/Toolbox.html
> Source code included, copy freely whatever you can use.
> --
> http://www.kynosarges.de



Mon, 31 Oct 2005 00:06:27 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Programmatically Launch a client's default email program

2. Howto launch the default email client?

3. Howto launch the default email client?

4. How do I launch the Default Email Client ?

5. Howto launch the default email client?

6. How do I launch the Default Email Client ?

7. is there any way to send email through a formal without launching the email client

8. Emailing using the default email client

9. How can I send email to the default email client outbox

10. Send Email to a Specific Address via Default Email Client

11. vb launch default mail client with an attachment.

12. HOW? Launch Default Mail Client

 

 
Powered by phpBB® Forum Software