Gmailに一定期間の間にのみ届いた添付ファイルをもったメールから添付ファイルを保存したいです。
期間は月初めから実行する前日までです。
変数に取りたい期間を入れてフィルターとすることを考えたのですが、メールの添付ファイルを保存の条件で日付が決められた日数しか選べないためできませんでした。
何か方法はあるでしょうか?
Hi @ru-32
- Set up Gmail authentication: Use the “G Suite Application Scope” activity to authenticate with your Gmail account. Enter your credentials and authorize UiPath to access your Gmail account.
- Retrieve emails within the desired period: Use the “Get IMAP Mail Messages” activity within the “G Suite Application Scope” to retrieve emails from Gmail. Set the appropriate parameters, such as the email folder, search query, and the number of messages you want to retrieve.To specify the desired period, you can construct a search query using the “Search Query” property. For example, if you want to retrieve emails from the beginning of the month until the day before execution, you can use the following search query:
"after:" + new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy/MM/dd") + " before:" + DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd")
This query searches for emails after the first day of the current month and before the current day (excluding the current day).
3. Iterate through retrieved emails: Use a “For Each” activity to loop through the retrieved emails. Set the “TypeArgument” to “System.Net.Mail.MailMessage” and provide the retrieved email messages as the input.
4. Save attachments: Within the loop, use the “Save Attachments” activity to save the attachments from each email to the desired location on your machine. Configure the activity to save the attachments based on your requirements.
5. Execute the automation: Run the automation and it will retrieve the emails within the specified period and save their attachments to the designated location.
Hope it helps!!
こんにちは
繰り返し(メール)でのフィルターで90日くらいで指定しておいて
条件分岐で必要な日付だけを処理をする手もあります。下記参照ください。
当月初日(1日)の処理が少々不明確かと思いますので、下記では当月1日は前月分を処理しています。
previsousDay = Today.AddDays(-1)
CurrentMail.DateAsDateTime>=New DateTime(previousDay.Year,previousDay.Month,1) AndAlso CurrentMail.DateAsDateTime<=previousDay
ありがとうございます。Gsuiteを使用したことが無かったので試してみます!
ありがとうございます!無事にできました。
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.