Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

send email in outlook using vb.net

Posted on 2004-09-02
18
Medium Priority
?
649 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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