Solved

send email in outlook using vb.net

Posted on 2004-09-02
18
621 Views
Last Modified: 2008-06-04
hello anyone know how to send an email in vb.net through outlook using the outlook 9.0 reference.  i dont want to use any dlls, just the outlook refernece... it is to send html formated mail.  thanks
0
Comment
Question by:christampa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
  • +2
18 Comments
 
LVL 5

Expert Comment

by:thenrich
ID: 11964294
It would be easier to prolly use the .NET mail provider. The reason being is if you have the latest service patches you'll get warnigs form the OS when sending mail. It's already there no additional dll's

example of FTP sending a document

  Private mailServer As System.Web.Mail.SmtpMail
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
        Try
            Dim strDocPath As String = GetDocPath()
            Dim strSendTo As String
            Dim strMessage As String

            If Not strDocPath Is Nothing Then
                Dim frmSendTo As New frmSendTo(PAR_ProjectManager)

                frmSendTo.GetSendToInfo()
                strSendTo = frmSendTo.arrInfo(0)
                strMessage = frmSendTo.arrInfo(1)
                frmSendTo.Close()

                If Not strSendTo = "" Then
                    Cursor.Current = Cursors.WaitCursor
                 
                    Dim newAtt As New System.Web.Mail.MailAttachment(strDocPath)
                    Dim newMail As New System.Web.Mail.MailMessage
                    mailServer.SmtpServer = "MailServer"
                    newMail.Subject = "Subject text"
                    'newMail.From = SystemInformation.UserName & "test@something.com"
                    'newMail.To = strSendTo
                    newMail.From = "test@something.com"
                    newMail.To = "test@something.com"

                    newMail.Body = strMessage
                    newMail.Attachments.Add(newAtt)
                    mailServer.Send(newMail)
                End If
            Else
                MsgBox("File " & strErrorPath & " could not be found." & Chr(13) & _
                "Make sure project has not been archived and verify file path exists .", _
                MsgBoxStyle.Exclamation)
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Cursor.Current = Cursors.Default
        StatusBar1.Panels(0).Text = "   Ready"
    End Sub
0
 
LVL 3

Author Comment

by:christampa
ID: 11964380
will that work for html based emails?  also the number of characters will go to 50000.  will that be ok?
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964419
I've never used it for html emails but I can't see why it wouldn't work.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 11964429
set mail body fromat to HTML

newMail.BodyFormat = MailFormat.Html
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964448
try this
Mail.BodyFormat = MailFormat.Html
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964460
Sorry YZlat - I did refresh before you posted.
0
 
LVL 3

Author Comment

by:christampa
ID: 11964561
do i need any references.  i get a lot of errors with that code.
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964604
what errors and where.
It wasn't meant to be a 'copy and paste' snippet rather an example.
0
 
LVL 3

Author Comment

by:christampa
ID: 11964685
System.Web.Mail.SmtpMail not defined
GetDocPath not declared
frmSendTo not defined
System.Web.Mail.MailAttachment not defined
System.Web.Mail.MailMessage not defined
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 11964697
I agree with using the .net provider. But many way here is the outlook version

        Dim olApp As Outlook.Application
        Dim olMail As Outlook.MailItem
        olApp = New Outlook.Application

        olMail = olApp.CreateItem(Outlook.OlItemType.olMailItem)
        olMail.Recipients.Add("bla.bla@bla.com")
        olMail.Subject = "Your subject"
        olMail.HTMLBody = "Your HTML text"
        olMail.Attachments.Add("c:\ttt.txt", Outlook.OlAttachmentType.olByValue)
        olMail.Send()
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11964707
But many way here is the outlook version

should ofcourse be

But anyway here is the outlook version

0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964735
reference system.web

 mailServer.SmtpServer = "Mailserver"
                    newMail.From = "someone@somplace.com"
                    newMail.To = "someone@somplaceelse.com.com"
                    newMail.Subject = "Test Subject"
                    newMail.Body = "bla, bla bla"
                    newMail.BodyFormat = Web.Mail.MailFormat.Html
                    mailServer.Send(newMail)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11964781
You need to add a System.Web reference to your project.

Bob
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11964808
I said that .... :-)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11964835
And, yes you did.  :)

Bob
0
 
LVL 3

Author Comment

by:christampa
ID: 11965335
ronald i am trying your way and get the error
'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_Event'.
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11965398
yea you'll get that cause there is a send method and a send a event handle. try late binding your mailitem. You'll still run into the securtiy issue using outlook...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_ol2003_ta/html/odc_olsendemailsprogrammatically.asp
0
 
LVL 3

Author Comment

by:christampa
ID: 11996887
thank you for all your help, but I am going to use  RonaldBiemans answer.  thanks

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question