Question

Email in VB

Asked by: Skwerlz

I need a full blown email client. I need to check it, download to local sytem, manage it, send mail, and anything else to do with it.
I need something similar to outlook, but I need it integrated into the project. Is there a way to correlate with outlook itself, integrate outlook into my project, or a component suite that would have what I need?
Any help, would be uber sweet!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-07 at 18:25:07ID24033729
Tags

visual basic

,

email

,

client

Topic

Visual Basic Programming

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Using Excel Correl Function in VB
    I have a VB app (6.0) that uses the Excel Correl function to find the correlation between two sets of numbers. The function has been working fine for years until this month when it seems to have reached it's "limit". Normally, the sets of numbers that I send into ...
  2. Auto emails with VB in Outlook
    I have done some basic VB stuff in Excel but never in Outlook. I am a small bookseller and I want to do some basic stuff, like have OUtlook automatically generate a follow-up email to customers a couple of weeks after they buy a book (I have an Excel file with customer info) ...
  3. Coefficient of Correlation in pivot table
    Coefficient of correlation I want to set up a pivot table with X and Y values where the pivot between those 2 values is the coefficient of correlation. It is a geological table with coeff. of corr. between Gold and Copper etc. My level of experties is intermediate in Access ...
  4. Send simple email without outlook using vb
    I developing a simple database system using vb6 and microsoft access. When user submit their request, the system will send a simple email to notify. How can i do that in a very simple way without involving Outlook? The email should contain the sender name (which would be fix,...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sirbountyPosted on 2009-01-08 at 07:07:59ID: 23325616

You can interact with Outlook.  You'll need to reference the correct library:

Outlook 97      "Microsoft Outlook 8.0 Object Library"      msoutl8.olb
msoutl8.olb      "Microsoft Outlook 98 Object Library"      msoutl85.olb
Outlook 2000      "Microsoft Outlook 9.0 Object Library"      msoutl9.olb
Outlook 2002      "Microsoft Outlook 10.0 Object Library"      msoutl.olb
Office Outlook 2003      "Microsoft Outlook 11.0 Object Library"      msoutl.olb


See http://support.microsoft.com/kb/220595 for more information...

 

by: mdouganPosted on 2009-01-08 at 07:32:50ID: 23325940

Yes, you can interact with Outlook programatically through VB.  You can make attachments, send e-mails, move mails around to different folders, open e-mails.

If you need this inside of the GUI for your application, it's a bit of work, but you can do it.  It's probably better just to let them use the GUI in Outlook.

For any of this to work, you obviously need Outlook installed on the machine, and, the user has to have an Outlook account on the Exchange Server.

You don't absolutely need Outlook to send e-mail through VB, there are other options such as SMTP mail. But, to receive mail, Outlook is probably your best bet.

What version of VB are you working with?

 

by: sirbountyPosted on 2009-01-08 at 10:19:30ID: 23328042

Not to mention, if I recall correctly, using Outlook in VB to send mail will generate the constant security warning (a program is trying to send mail on your behalf...blah blah blah).

 

by: SkwerlzPosted on 2009-01-08 at 11:29:56ID: 23329033

I am using visual studio 2008
It was part of my payment for taking on  the project, which is a awesosome upgrade from vb express.
Unfortunately, my only experience is with express, and very limited. I am learning on the fly. Most of my experience is with flash actionscript, so I can learn quick. I just need to pointed into the right direction.

 

by: sirbountyPosted on 2009-01-08 at 11:32:45ID: 23329086

Ah, a bit easier with .Net you'll be delighted to know. :^)

I'm not on VS08 yet tho (still 05 until I convince management), but this should be a good starter/example(s) for you:

http://www.codeproject.com/KB/aspnet/extract_oulook_2003_NET.aspx
http://forums.devx.com/archive/index.php/t-77625.html
http://msdn.microsoft.com/en-us/library/aa168454.aspx

 

by: mdouganPosted on 2009-01-08 at 12:47:09ID: 23329980

The attached code is an example of a routine for sending an e-mail with Outlook.  It might generate that annoying message about sending mail on your behalf... seems like we got around that somehow...  anyway, a large part of the code is dedicated to code necessary to save the e-mail in a particular draft folder, if the user doesn't want to send it out straight away.  I include it because it gives you an example of iterating through a users folders and working with them.

Note, if you specify a mailbox or folder name that doesn't exist, it typically throws an error, in which case you have to trap the error... so, you'll note the multi-level error handling.

Imports Microsoft.Office.Interop
Imports System.IO
 
Public Class Office
 
 
    Public Sub SendMAPIEmail(ByVal sFrom As String, ByVal sTo As String, ByVal sCC As String, ByVal sBCC As String, _
            ByVal sSubject As String, ByVal sBody As String, ByRef sAttachment() As String, _
            Optional ByVal Preview As Boolean = False, Optional ByVal bSave As Boolean = False, Optional ByVal move_to_folder As String = "", _
            Optional ByVal HighImport As Boolean = False, Optional ByVal HTMLBody As String = "")
 
        Dim objOutlook As New Microsoft.Office.Interop.Outlook.Application
        Dim objMail As Microsoft.Office.Interop.Outlook.MailItem
        Dim objAttachment As Microsoft.Office.Interop.Outlook.Attachment
        Dim i As Int32
        Dim mfolder As Outlook.MAPIFolder
        Dim errmsg As String
 
        Try
 
            ' Logon to Outlook
            objOutlook.Session.Logon()
            
            ' Create new e-mail item and populate
            objMail = objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
            objMail.SentOnBehalfOfName = sFrom
            objMail.To = sTo
            objMail.CC = sCC
            objMail.BCC = sBCC
 
            objMail.Subject = sSubject
 
            objMail.Body = sBody
                        
            ' Set the importance if necessary
            If HighImport Then objMail.Importance = Outlook.OlImportance.olImportanceHigh            
            
            If HTMLBody <> "" Then objMail.HTMLBody = HTMLBody
 
            ' sAttachment is a string array of file path/names to attach
            If Not IsNothing(sAttachment) Then
                For i = LBound(sAttachment) To UBound(sAttachment)
                    If File.Exists(sAttachment(i)) Then
                        objAttachment = objMail.Attachments.Add(sAttachment(i))
                    Else
                        MsgBox("You are attempting to attach a file that does not exist: " & sAttachment(i) & " The e-mail will be generated without this attachment.", MsgBoxStyle.Information, "Generate E-Mail")
                    End If
                Next
            End If
 
            ' If the user is going to preview before sending the e-mail, then save it as a draft and open Outlook for display
            If Preview Then
                If bSave Then
                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Save()
                End If
 
                CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Display()
            Else
                ' If directed to save into another folder, then save it as a draft then move it to the appropriate folder
                If bSave Then
                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Save()
 
                    ' On our exchange server, we might have a mailbox named 'Purchase Orders' so, we would navigate to that folder
                    ' then save the e-mail in the Draft folder under that mailbox
                    If move_to_folder <> "" Then
                        'for "Mailbox - xxx"
                        Try
                            mfolder = objOutlook.GetNamespace("MAPI").Folders(move_to_folder)
                            mfolder = mfolder.Folders("Drafts")
                            CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Move(mfolder)
 
                        ' If the folder doesn't exist, or this user isn't a member of that group, then it will generate an error
                        ' so, you have to have A LOT of error handling
                        Catch x As Exception
 
                            errmsg = x.Message
                            Try
                            
                                ' Sometimes a particular mailbox might appear as  "Purchase Orders', sometimes as 'Mailbox - Purchase Orders'
                                ' so, if the first try didn't succeed, then try again without the 'Mailbox -'
                                If move_to_folder.StartsWith("Mailbox - ") Then
                                    move_to_folder = Replace(move_to_folder, "Mailbox - ", "")
                                    mfolder = objOutlook.GetNamespace("MAPI").Folders(move_to_folder)
                                    mfolder = mfolder.Folders("Drafts")
                                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Move(mfolder)
                                Else
                                    MsgBox("Cannot Find Mailbox " & move_to_folder & " Will display the E-Mail being generated for you to save to another location. " + errmsg, MsgBoxStyle.Information)
                                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Display()
                                End If
 
                            Catch ex As Exception
 
                                MsgBox(ex.Message)
                                Try
                                    Dim oFolder As Outlook.MAPIFolder
                                    For Each oFolder In objOutlook.GetNamespace("MAPI").Folders
                                    
                                        ' If finding the folder by the exact name didn't work, then loop through all the folders they have
                                        ' looking for one that might have a similar name
 
                                        If move_to_folder.IndexOf("Purchase") > -1  And oFolder.Name.IndexOf("Orders") > -1 Then
                                            mfolder = oFolder
                                            mfolder = mfolder.Folders("Drafts")
                                            CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Move(mfolder)
                                            Exit For
                                        End If
 
                                        If move_to_folder.IndexOf("Invoice") > -1 And oFolder.Name.IndexOf("Orders") > -1 Then
                                            mfolder = oFolder
                                            mfolder = mfolder.Folders("Drafts")
                                            CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Move(mfolder)
                                            Exit For
                                        End If
 
                                    Next
 
                                Catch exx As Exception
                                
                                    ' If that didn't work, then give up and display the e-mail to the user with an error message about being
                                    ' unable to save it to the Draft folder
                                    
                                    MsgBox(exx.Message)
                                    MsgBox("Cannot Find Mailbox " & move_to_folder & " Will display the E-Mail being generated for you to save to another location.", MsgBoxStyle.Information)
                                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Display()
                                End Try
                            End Try
                        End Try
 
                    End If
                Else
                    ' Or, just send the e-mail out directly, without bothering to save it to any folder (will end up in Sent Items)
                    CType(objMail, Microsoft.Office.Interop.Outlook._MailItem).Send()
                End If
            End If
 
        Catch x As Exception
            MsgBox(x.Message)
        Finally
            ' You don't need to Quit outlook... that might kill the users session if they have it open
            'CType(objOutlook, Microsoft.Office.Interop.Outlook._Application).Quit()
            
            ' But, you need to release the marshalled resources of the COM objects
            NAR(objOutlook)
            NAR(objMail)
            NAR(objAttachment)
            GC.Collect()
        End Try
 
    End Sub
    
        Private Sub NAR(ByVal o As Object)
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
            Catch x As Exception
                'MsgBox(x.Message)
            Finally
                o = Nothing
            End Try
        End Sub
End Class

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:

Select allOpen in new window

 

by: sirbountyPosted on 2009-01-08 at 12:49:03ID: 23330007

"seems like we got around that somehow."

Either by using redemption, or the ClickYes application...

 

by: SkwerlzPosted on 2009-01-08 at 15:42:31ID: 23331435

Thanks a ton Guys!
Are ther any component suites that would work? I don't have a problem with using outlook, just wondering if there would be a better way to just interact with the mail server(smtp, pop3).
I have found plenty of tutorials on sending emails, but managing the mailbox not so much.
The main reason I am considering outlook is for syncing with mobile devices. Contacts, and Calendar mostly, but the company I am putting this together for is looking for an all in one type deal.

 

by: sirbountyPosted on 2009-01-08 at 15:52:45ID: 23331491

smtp only, you're better off using cdo, but you can't manage the mail like you want, which is why the advice is to use Outlook.

 

by: SkwerlzPosted on 2009-01-08 at 16:01:52ID: 23331550

That's cool.
Just a thought. With the syncing and everything, outlook would probably be easier anyway.
I guess the basic question I have with outlook are:
Getting around the warning
Sending a send/receive request
Calendar syncing
and Contact syncing.
I can start up some new questions on the calendar and contact deals.

 

by: SkwerlzPosted on 2009-01-08 at 16:03:40ID: 23331555

By syncing, I mean with my app, not the mobile devices.

 

by: sirbountyPosted on 2009-01-08 at 16:06:46ID: 23331574

Check out http://www.outlookcode.com/
There's some great code samples there for most of what you're looking for.  I never got around to trying out the redemption piece, but currently only use the calendar syncing, which works brilliantly.  But I'm sure if you google it, you can find plenty of examples.  The problem with the "ClickYes" tool that you may find is that, imo, it's still very conspicuous.  The message will still appear, it just runs in the background waiting on the timer to end so that it can "click" for you - not very attractive...

I've never done any contact syncing, but would imagine you'll find a good bit about that on the web site as well...

 

by: SkwerlzPosted on 2009-01-08 at 16:18:45ID: 23331659

I dont suppose there is anyway to select trusted programs in outlook or anything like that?

 

by: SkwerlzPosted on 2009-01-08 at 16:23:07ID: 23331684

Actually Now that I am thinkig of it, I am using a mssql server to store my calendar.
Is there anyway to set outlook storages to sync with mssql?

 

by: sirbountyPosted on 2009-01-08 at 16:41:52ID: 23331779

Hmm - I'm not really sure.  I believe the PSTs are basically a sort of database, so I'd imagine it's doable.
If I recall (would have to check my code at work), each item (mail, contact, reminder, etc) has a unique string reference, like a GUID of sorts.  It's what I use to ensure there's no duplication with the calendar items that I sync, so I'd imagine it's very doable...

 

by: mdouganPosted on 2009-01-08 at 23:07:08ID: 23333340

"seems like we got around that somehow."

Either by using redemption, or the ClickYes application...

No, I know that we got around it by using a Web component, or, it seems to me that we got around it by authorizing a person to send e-mail on behalf of another person.  Here is an example of sending an e-mail using the web component...

    Public Sub SendSMTPEmail(ByVal sFrom As String, ByVal sTo As String, ByVal sSubject As String, ByVal sBody As String, Optional ByVal sCC As String = "", Optional ByRef sAttachment() As String = Nothing)
 
        Try
            Dim Msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
            Dim objAttachment As System.Web.Mail.MailAttachment
            Dim i As Int32
 
            Msg.From = sFrom
            Msg.To = sTo
            Msg.Subject = sSubject
            Msg.Body = sBody
            Msg.Cc = sCC
            Msg.BodyFormat = System.Web.Mail.MailFormat.Text
 
            If Not IsNothing(sAttachment) Then
                For i = LBound(sAttachment) To UBound(sAttachment)
                    If File.Exists(sAttachment(i)) Then
                        objAttachment = New System.Web.Mail.MailAttachment(sAttachment(i))
                        Msg.Attachments.Add(objAttachment)
                    Else
                        MsgBox("You are attempting to attach a file that does not exist: " & sAttachment(i) & " The e-mail will be generated without this attachment.", MsgBoxStyle.Information, "Generate E-Mail")
                    End If
                Next
            End If
 
            System.Web.Mail.SmtpMail.SmtpServer = MyHost
            System.Web.Mail.SmtpMail.Send(Msg)
 
        Catch e As Exception
            MsgBox("SendSMTPEmail() " + e.Message)
        Finally
 
        End Try
 
    End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:

Select allOpen in new window

 

by: SkwerlzPosted on 2009-11-03 at 17:47:23ID: 31649796

found a little bit of everything i needed

 

by: mdouganPosted on 2009-11-03 at 18:44:49ID: 25735960

hahaha, 11 months later.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...