0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerAutomateDesktopでメール作成

Last updated at Posted at 2024-12-01

備忘録として

 ・メール情報はExcelに記述
スクリーンショット 2024-12-02 031833.png

テンプレートファイルを利用してメール編集⇒下書き保存

 ・Outlookテンプレート(.oft)ファイルを使用
 ・メール作成後下書きに保存
 ・作成完了後に日付を入れてExcelを別名保存

設定は以下
スクリーンショット 2024-12-02 033220.png
スクリーンショット 2024-12-02 033334.png
スクリーンショット 2024-12-02 033410.png

FUNCTION Main_コピー GLOBAL
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    SET ExcelPath TO $'''C:\\RPA\\PAD\\Mail\\MailSetting.xlsx'''
    SET OutlookAppPath TO $'''C:\\Program Files\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE'''
    SET OutlookTemplatePath TO $'''C:\\Users\\Chabudai_Gaeshi\\Downloads\\メールの下書き.oft'''
    SET WorkFolder TO $'''C:\\RPA\\PAD\\Mail'''
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyyMMdd_HHmmss''' Result=> FormattedDateTime
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: ExcelPath Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Setting'''
    Excel.ReadFromExcel.ReadNamedCell Instance: ExcelInstance CellName: $'''SendList''' ReadAsText: False TrimEmptyCells: False RangeValue=> ExcelData
    LOOP FOREACH CurrentItem IN ExcelData
        IF CurrentItem[0] <> $'''#''' THEN
            IF IsNotEmpty(CurrentItem[2]) THEN
                System.RunApplication.RunApplicationAndWaitToLoad ApplicationPath: OutlookAppPath CommandLineArguments: $'''/t %OutlookTemplatePath%''' WorkingDirectory: WorkFolder WindowStyle: System.ProcessWindowStyle.Normal Timeout: 0 ProcessId=> AppProcessId
                WAIT 1
                DISABLE MouseAndKeyboard.SendKeys.FocusAndSendKeysByInstanceOrHandle WindowInstance: WindowHandle TextToSend: $'''{Shift}({Tab})''' DelayBetweenKeystrokes: 30 SendTextAsHardwareKeys: False
                MouseAndKeyboard.SendKeys.FocusAndSendKeys TextToSend: $'''%CurrentItem[2]%{Tab}''' DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False
                MouseAndKeyboard.SendKeys.FocusAndSendKeys TextToSend: $'''%CurrentItem[3]%{Tab}''' DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False
                MouseAndKeyboard.SendKeys.FocusAndSendKeys TextToSend: $'''%CurrentItem[4]%{Tab}''' DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False
                MouseAndKeyboard.SendKeys.FocusAndSendKeys TextToSend: CurrentItem[5] DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False
                MouseAndKeyboard.SendKeys.FocusAndSendKeys TextToSend: $'''{Control}({S}){Alt}({F4})''' DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False
                Variables.ModifyDataTableItem DataTable: ExcelData ColumnNameOrIndex: 1 RowIndex: CurrentItem[0] Value: FormattedDateTime
            END
        END
    END
    LOOP FOREACH CurrentItem IN ExcelData
        IF CurrentItem[0] <> $'''#''' THEN
            IF CurrentItem[1] = FormattedDateTime THEN
                Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: CurrentItem[1] Column: 2 Row: CurrentItem[0] + 1
            END
        END
    END
    Text.Replace Text: ExcelPath TextToFind: $'''.xlsx''' IsRegEx: False IgnoreCase: False ReplaceWith: $'''_%FormattedDateTime%.xlsx''' ActivateEscapeSequences: False Result=> ExcelSavePath
    Excel.CloseExcel.CloseAndSaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: ExcelSavePath
END FUNCTION

テンプレートを使用せずメール作成

 ・Outlookを起動してメールを作成して保存
image.png

IF IsNotEmpty(CurrentItem[2]) THEN
    Outlook.Launch Instance=> OutlookInstance
    Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''chabudai.gaeshi@harapeko.com''' SendTo: CurrentItem[2] CC: CurrentItem[3] Subject: $'''%FormattedDateTime% %CurrentItem[4]%''' Body: CurrentItem[5] IsBodyHtml: False IsDraft: True
END
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?