General discussion

Locked

Email Attachments Automation

By Parli Singh ·
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).

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Email Attachments Automation

by andrew In reply to Email Attachments Automat ...

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.

Collapse -

Email Attachments Automation

by Parli Singh In reply to Email Attachments Automat ...

Poster rated this answer

Collapse -

Email Attachments Automation

by Parli Singh In reply to Email Attachments Automat ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums