Discussion Locked

Email Attachments Automation

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I receive an email daily which has a file attached with Stats, Is it possible to automate the process of getting the email and saving the attachment (i.e opening the Email attachment and saving it).

3 replies

by andrew

Here's a VB method that uses the CDONTS library (set a reference to CDONTS.DLL):

Dim oSession As CDONTS.Session
Dim oFolder As CDONTS.Folder
Dim oMessages As CDONTS.Messages
Dim oMessage As CDONTS.Message
Dim oAttachments As CDONTS.Attachments
Dim oAttachment As CDONTS.Attachment

Set oSession = New CDONTS.Session
oSession.LogonSMTP "Andrew", "awilliams@medcases.com"
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)
Set oMessages = oFolder.MessagesFor Each oMessage In oMessages
If oMessage.Subject = "something" Then
Set oAttachments = oMessage.Attachments
For Each oAttachment In oAttachments
oAttachment.WriteToFile "filename.ext" Next
End If
Next

oSession.Logoff

This will loop through all the messages in your inbox, looking for one with a specific subject. When it finds it, it will loop through the attachments and save them. (you may want to make sure the names are unique if you expect more than one attachment)

Hope this helps.

This discussion is closed to new replies.