how to send an email from your default e-mail

hi,#

can any one give me an example on how to use mapi in vb.net or how can i send an email using the default email in vb.net


thanks

LVL 8
gajender_99Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
RonaldBiemansConnect With a Mentor Commented:
You mean the mailto ?

Process.Start("mailto:bla.bla@bla.com?subject=test&body=test&attachment='c:\test.gif'")

but this won't auto send, I don't thing you can do that with mailto:
0
 
RonaldBiemansCommented:
This is the easiest way
dim s as string = "bla.bla@bla.com"
 Process.Start("mailto:" & s)
0
 
gajender_99Author Commented:
hi,

can your give me more information how to attach a file, subject and body also

and if possible auto send

i would give extra points for this
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RonaldBiemansCommented:
Ah, then you have to go a completly different way. Here is one

Imports System.Web.Mail

    Friend Function SendEmail(ByVal strAppSending As String, ByVal strErrMsg As String) As String
        Dim strAnswer As String = "False"
        Try
            Dim Mail As SmtpMail
            Dim MailMsg As New MailMessage()

            With MailMsg
                '   .To = "cbsse_appmsg@Mail.com"
                .To = "<programmers email address>"
                .Cc = "<programmers email address>"
                .From = strAppSending + "@<Company Name>.com"
                .BodyFormat = MailFormat.Html
                .Priority = MailPriority.High
                .Subject = "App Error"
                .Body = strErrMsg
            End With
            SmtpMail.SmtpServer = "<your SMTP servers IP address>"
            SmtpMail.Send(MailMsg)

            Mail = Nothing
            MailMsg = Nothing
            strAnswer = "True"
        Catch
            strAnswer = Err.Description + ". From Global Function { SendEmail}"
        End Try
        SendEmail = strAnswer
    End Function
0
 
gajender_99Author Commented:
hi
 i like the first one but how can you attach a file to it
0
 
Éric MoreauSenior .Net ConsultantCommented:
The mailto protocol almost never allow attachments.
0
 
RonaldBiemansCommented:
Remember aswell, that the attachment property doesn't work on all email clients. In the second example I gave, it will. Plus you can use autosend.
0
 
RonaldBiemansCommented:
Ah, sorry emoreau, I didn't see your comment
0
 
iboutchkineConnect With a Mentor Commented:
THis is an example how to use MAPI controls

'add 2 controls
Microsoft MAPIMessages (call it MAPIMessages1)
Microsoft MAPISession (call it MAPILogOn)
(AxInterop.MSMAPI.dll,  Interop.MSMAPI.dll)


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
 
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim msg As String

        msg = "This is a test email from Iouri."
        With Me
            .MAPILogOn.SignOn() ' use current user
            Do While .MAPILogOn.SessionID = 0
                System.Windows.Forms.Application.DoEvents() ' need to wait until the new session is created
            Loop
            Call SendToEmail("someone@somewhere.com", msg)
            .MAPILogOn.SignOff()
        End With
        MsgBox("e-mail is sent")

    End Sub

    Private Sub SendToEmail(ByVal Email As String, ByVal msg As String)
        With MAPIMessages1
            'create a new message and address it
            .SessionID = MAPILogOn.SessionID
            .Compose()
            .RecipDisplayName = Email
            .AddressResolveUI = True
            .RecipAddress = "smtp:" & Email
            .MsgSubject = "VB GENERATED E-MAIL"
            .MsgNoteText =msg
            .Send(False)
        End With
    End Sub

End Class
0
 
gajender_99Author Commented:
as i havent got a proper answer i would split the points

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.