PowerAutomateDesktopでメール作成

# 備忘録として
　・メール情報はExcelに記述
![スクリーンショット 2024-12-02 031833.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/96938/027b5c2e-4394-641e-7ee6-c0929ce3ad3d.png)

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

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

設定は以下
![スクリーンショット 2024-12-02 033220.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/96938/8271ddeb-69bd-81c6-11cc-95a1537e0241.png)
![スクリーンショット 2024-12-02 033334.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/96938/17dc77d2-3b5e-5e8a-e029-17b42ec2f204.png)
![スクリーンショット 2024-12-02 033410.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/96938/19fec38d-52cb-6cea-0741-322c22872439.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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/96938/a8ae1087-acca-9ae0-31a1-602b04a779f9.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