Solved

send email in outlook using vb.net

Posted on 2004-09-02
18
623 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
Industry Leaders: 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

Technology Partners: 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!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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