1 Attachment(s)
VB6.0 - Office Outlook mail retrieval
Hi,
This is a Visual Basic 6.0 example I created back in 2005. This example shows you how to use the mapi components in VB to take advantage of Office Outlook (2003)'s email abilities. The MSMapi32.ocx is required in order for the code to work properly.
Code:
frmAttachments
vb Code:
'Copyright 2005 "nightwalker83"
Private Sub cmdAttach_Click()
CDFiles.ShowOpen
txtFile.Text = CDFiles.FileName
LstFiles.AddItem CDFiles.FileName
lblCount.Caption = lblCount.Caption + 1
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
For r = 0 To LstFiles.ListCount - 1
LstFiles.RemoveItem (0)
lblCount.Caption = lblCount.Caption - 1
Next r
txtFile.Text = ""
End Sub
Private Sub cmdDone_Click()
Me.Hide
End Sub
Private Sub Form_Load()
txtFile.Locked = True
End Sub
frmCompose
vb Code:
Private Sub cmdAttach_Click()
'Show attachments.
frmAttachments.Show vbModal, Me
End Sub
Private Sub cmdClear_Click()
'Clear all fields.
txtTO.Text = ""
txtSubject.Text = ""
txtBody.Text = ""
End Sub
Private Sub cmdClose_Click()
'Unload the form.
Unload Me
End Sub
Private Sub cmdSend_Click()
'Check whether or not to save then send the message.
frmMain.MAPIMessages1.MsgIndex = -1
frmMain.MAPIMessages1.RecipAddress = txtTO.Text
'Double checks that address is valid.
frmMain.MAPIMessages1.ResolveName
frmMain.MAPIMessages1.MsgSubject = txtSubject.Text
frmMain.MAPIMessages1.MsgNoteText = txtBody.Text
'Check for attachments.
If frmAttachments.LstFiles.ListCount <> 0 Then
For a = 0 To frmAttachments.LstFiles.ListCount - 1
For S = 1 To (frmAttachments.LstFiles.ListCount)
sp = Split(frmAttachments.LstFiles.List(a), "\")
frmMain.MAPIMessages1.AttachmentName = sp(S)
Next S
frmMain.MAPIMessages1.AttachmentIndex = (a)
frmMain.MAPIMessages1.AttachmentPosition = (a)
frmMain.MAPIMessages1.AttachmentPathName = frmAttachments.LstFiles.List(a)
Next a
End If
'Save the message.
If chkSave.Value = 1 Then
frmMain.MAPIMessages1.Save
End If
'Send the message.
frmMain.MAPIMessages1.Send (False)
End Sub
frmMain
vb Code:
Private Sub Form_Load()
Dim itmM As ListItem, MCount As Variant, MsgCount As Variant, COLH As Integer
'Logon to your Email account.
MAPISession1.LogonUI = True
'Sign in to your email account.
MAPISession1.SignOn
'Make sure the messages are used in the current session.
MAPIMessages1.SessionID = MAPISession1.SessionID
'Download new mail from inbox.
MAPISession1.DownLoadMail = False
MAPIMessages1.FetchUnreadOnly = True
MAPIMessages1.Fetch
'Sort the messages.
MAPIMessages1.FetchSorted = True
'Check how many messages were received.
MCount = MAPIMessages1.MsgCount
'Show received messages.
For MsgCount = 0 To MCount - 1
Next MsgCount
'Adjusts the index of each column so it can display the correct information.
For COLH = 0 To 2
Set itmM = LstNewMail.ListItems.Add(, , MAPIMessages1.MsgOrigAddress)
COLH = COLH + 1
itmM.SubItems(COLH) = MAPIMessages1.MsgSubject
COLH = COLH + 1
itmM.SubItems(COLH) = MAPIMessages1.MsgDateReceived
Next COLH
frmMain.Caption = frmMain.Caption & " " & "You have " & MsgCount & " new messages!"
frmMain.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Sign out of your email account.
MAPISession1.SignOff
End Sub
Private Sub mnuAddress_Click()
'Opens the address book.
On Error Resume Next
MAPIMessages1.Show
End Sub
Private Sub mnuCompose_Click()
'Compose a new email message.
frmCompose.Show vbModal, Me
End Sub
Private Sub mnuExit_Click()
'Exit the application.
Unload Me
End
End Sub
Private Sub mnuReadMessages_Click()
'Opens the form so you can read any new emails.
frmRead.Show vbModal, Me
End Sub
frmRead
vb Code:
Private Sub cmdClose_Click()
'Unload the form.
Unload Me
End Sub
Private Sub cmdDelete_Click()
'Deletes current message.
frmMain.MAPIMessages1.Delete
txtBody.Text = ""
txtSubject.Text = ""
txtFrom.Text = ""
frmMain.Refresh
End Sub
Private Sub Form_Load()
'Locked the text disable the textboxes so they are read only.
txtFrom.Enabled = False
txtSubject.Enabled = False
txtBody.Locked = True
'Get information from the message so it can be read.
txtFrom.Text = frmMain.MAPIMessages1.MsgOrigAddress
txtSubject.Text = frmMain.MAPIMessages1.MsgSubject
txtBody.Text = frmMain.MAPIMessages1.MsgNoteText
'If there are no more messages disable the delete button.
If frmMain.MAPIMessages1.MsgCount = "0" Then
cmdDelete.Enabled = False
End If
End Sub
Module1
vb Code:
Public a As Integer
Public Path As String
Nightwalker
Re: VB6.0 - Office Outlook mail retrieval
In-order to bypass the security restrictions in office outlook/outlook express you can either try and use a work around such as Redemption or you can uninstall office outlook/outlook express whichever you use and install Windows Live Mail. Windows Live Mail does not have the same security patch applied to it as office outlook/outlook express does so the above code will work without any issues.
Re: VB6.0 - Office Outlook mail retrieval
11/07/2010 - See first post for updated attachment! Rewrote the code so that it uses redemption instead of simple mapi. Download redemption from the above url and reference it in the project in-order to use the code.
Re: VB6.0 - Office Outlook mail retrieval
1. you called the sendmail sentmail, so it's a bug, but this is a small thing.
2. i get an error 429: "ActiveX component can't create object"
Re: VB6.0 - Office Outlook mail retrieval
Quote:
2. i get an error 429: "ActiveX component can't create object"
You need to download the "Developer" version of Redemption from the above site and install it. Once it is installed reference it in the project.
Edit:
I fixed the send mail problem.
Also, the code does not work without outlook installed! I have suggested this could be changed in the next version of Redemption if say Windows Live Mail is only installed. My original code worked regardless of whether or not outlook was installed on the system.
Re: VB6.0 - Office Outlook mail retrieval
aha
i don't have outlook
1. i already downloaded the developer version, and extracted only the dll without using install.
and the references worked ok, but i got this error, i think because i miss some mapi component
that comes with outlook.
i read in the redemption site that if i don't have outlook i need to download something from microsoft,
i'll check this when i'll have time.
Re: VB6.0 - Office Outlook mail retrieval
Quote:
Originally Posted by
whatsup
aha
i don't have outlook
1. i already downloaded the developer version, and extracted only the dll without using install.
and the references worked ok, but i got this error, i think because i miss some mapi component
that comes with outlook.
i read in the redemption site that if i don't have outlook i need to download something from microsoft,
i'll check this when i'll have time.
I'm in the same boat! On my Laptop I only have Windows Live Mail installed.
On the redemption home page it says:
Quote:
If you are planning to use the RDO family of objects on a Windows server that does not have Outlook, Exchange Server or Exchange Admin installed, you will need to install the standalone version of MAPI from the Microsoft site.
There is a download link for the standalone version of MAPI next to the text. The file is ExchangeMapiCdo.
Edit:
I think I have to rewrite the program to use ExchangeMapiCdo because I installed it on my laptop and my program still failed. Although, maybe that was because ExchangeMapiCdo wasn't referenced in the project.
Re: VB6.0 - Office Outlook mail retrieval
I have found some third party components that I can use to send and receive email without outlook. I will start a new thread in the codebank when I have converted all the functions to work without outlook. We Only Do are the components I'm using.
Edit:
The updated version of the code can be found here.
Re: VB6.0 - Office Outlook mail retrieval
Public RDOSession As Redemption.RDOSession
what am i missing what is the refference for this
Re: VB6.0 - Office Outlook mail retrieval
Quote:
Originally Posted by
ladoo
Public RDOSession As Redemption.RDOSession
what am i missing what is the refference for this
You need to install and reference Redemption in your project! See post #2.
Re: VB6.0 - Office Outlook mail retrieval
Is this working with SSL authentication like gmail?
Re: VB6.0 - Office Outlook mail retrieval
Quote:
Originally Posted by
green.pitch
Is this working with SSL authentication like gmail?
See my reply in post #18 here.