Download email attachments from a gmail account

Hello,

I want to creat a script that allow me to connect to a gmail adresse in order to download mail attachments and store them is a local folder.

Do you guys have any tips, info or even a script that does this?

 

Thanks in advance and sorry for my english.

Well, I literally just googled your question’s header and got this.

Hello Noka40,

What did you already try?

As .NET do not contain classes to manipulate with the mailbox and read emailh, you have 2 options:

  1. Use custom email client library which implements basic email client using IMAP or POP protocols (something along those lines that Lars is suggesting)

  2. Use Google API to access the mailbox and download attachments. For more information please go here.

Hope that helps.

Hello Lars and Andy,

Thank you for your messages!

I wanted to use ImapX in order to interract with my mails but i am unable to install it or understand how to install or add it.

It seems like you need to use a dll that you download on the website but here i am with two of the different package that you can download on the website and none of them have a dll file.

 

Am I missing something?

 

I went through the whole “discussions” and “issues” topic without anything information about install or implement it to powershell.

 

What am i doing wrong?

There’s a Commounity Module named PSGsuite that will make this simple.

https://psgsuite.io/Initial%20Setup/

Follow the instructions there to install the module and to authorize it to interact with your GSuite. Once you have it installed you’ll need to use 2 commands.

Get-GSGmailMessage and Get-GSGmailMessageList

Get-GSGmailMessageList will let you search for email stub records and obtain an ID to be used by Get-GSGmailMessage.

Get-GSGmailMessage will let you retrieve the actual email based on the user account you want to access and the ID of the email.

All together it will look something like:

$EmailID = (Get-GSGmailMessageList -Filter { subject:"Email Subject" } | Select-Object -First 1).id

$EmailAttachment = Get-GSGmailMessage -User user@domain.com -Id $EmailID -SaveAttachmentsTo c:\temp


See examples here:
https://psgsuite.io/Function%20Help/Gmail/Get-GSGmailMessageList/

https://psgsuite.io/Function%20Help/Gmail/Get-GSGmailMessage/

Hello,

 

I think that i will aim for a linux solution.

I find out that mutt on linux is can do it, i will just have to create my own script.

I am still interested in this imapx solution.