Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving/Sending E-Mail 1

Status
Not open for further replies.

LostInCode

Programmer
Feb 4, 2004
216
DE
My application needs to send and receive e-mails with text file attachments automatically.

This means that when the user starts the application, the app looks for new e-mail with beginning with a certain ID, and if found, then looks for an attachment and if there is one, retrieves and stores it as a file locally for further processing.

The app will also automatically send e-mails with attachments.

Assumming the client has Outlook or Outlook Express (the client may or may not have the Outlook ActiveX control) under W98, ME, NT4/5, how can this be done in VB and where can I see some example code to look for e-mail messages?

Most examples I've seen use MAPI to just send e-mail. But that's all I've found.

Thank you!
 
You can't support Outlook Express; it doesn't have a programmable interface. Need Outlook and/or CDO 1.21. CDO 1.21 is part of a default install in OL98 but has to be selected in a custom install in OL2000 or later.

Have you searched this forum for Outlook (for example)? There are tons of code examples.

Paul Bent
Northwind IT Systems
 

Thanks for your help.

Yes I have seen you can do this with Outlook using the Outlook ActiveX component.

MAPI cannot be used with Outlook Express either?

So I need to make Outlook a requirement? <Sigh>
 
The Outlook ActiveX component is Outlook itself. There isn't a separate Outlook control you can distribute. The end user must have a licensed copy of Outlook installed.

Paul Bent
Northwind IT Systems
 
Yes, this I have understood, as I hit upon but didn't clearly point out in my leading question.

So, what you are saying there is no way to do this with Outlook Express?

 
The VB MAPI controls support Simple MAPI and will work with Outlook Express. Will be fine for sending mail but functionality is limited re accessing messages in MAPI folders; although you can retrieve items from the Inbox with it.

Paul Bent
Northwind IT Systems
 
If you can't make it a requirement that the user have Outlook (that would make your life a lot easier) and you end uip trying to support both environments you might want to look into a third party control. Could save you major work.

Just search for ActiveX mail control and you'll find plenty with free trials.



 
This seems to work in order to loop thru all mail and get attachments from an e-mail.

Code:
Public Sub EMAIL()
    Dim iMessages       As Integer
    Dim iAttachments    As Integer

    MAPISession1.SignOn
    With MAPIMessages1
        
        .SessionID = MAPISession1.SessionID
        .FetchSorted = True
        .Fetch
        
        For iMessages = 0 To .MsgCount - 1
            .MsgIndex = iMessages
            
            'LOOKING FOR A SPECIFIC E-MAIL
            If CDate(.MsgDateReceived) = CDate(#02/05/2004 12:00:05#) Then
[Blue]
Code:
                If Len(.AttachmentPathName Then)
[Black]
Code:
                    For iAttachments = 0 To MAPIMessages1.AttachmentCount - 1
                        .AttachmentIndex = iAttachments
                        debug.print .AttachmentPathName
                    Next iAttachments
                End If
            End If
        Next iMessages
    End With
    MAPISession1.SignOff
End Sub

The conditional statement in blue color was needed to &quot;activate&quot; the AttachmentCount property, otherwise it always showed 0.

Anyone know why?!!
 

Is this possibly a bug, or am I doing something wrong?
 

Can I then assume that this is then a bug and the only work a round is the one which I have posted?
Anyone?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top