LoginSignup
2
1

More than 1 year has passed since last update.

【Mac M1】applescriptを使って、全取引先に年末の挨拶メールを、一瞬で個別送信する方法。

Last updated at Posted at 2022-12-23

<愚痴>
まあ、Windows環境用に、PythonとWin32comを駆使して書くならば、需要はあるのでしょうが、自分の環境がMac環境なので、使えないApplescriptを駆使して、書きます。笑

<やりたい事>
タイトルが、「◯◯様、年末のご挨拶【海山商事、山田太郎】」と言う個別メールを、全取引先(300社以上)に、一斉送信したい。
(一般的には、BCCメールでやるのであろうが、「宛先多数の為、BCCメールで送信します。」とやると、経験上、誰も読まないし、第一、失礼だと思っております。)

内容は下記。

====
◯◯様、

いつも大変お世話になっております。
山田太郎です。
早いもので、本年も残りわずかとなり、年末のご挨拶をさせていただく時期となりました。

メールにて、恐縮ではございますが、年末のご挨拶とさせて頂きたいと思います。
良いお年をお迎えください。

山田太郎
====

<手順 1>
下記の様にで、送信したい相手先書いた.csvファイルを用意する。
A列にお客様の名前、B列にメールアドレス。
ファイル名は、recipient_list.csv

名称未設定3.jpg

上のファイルは、Desktop上に"Greeting"と言う名前のフォルダを作成し、そこに突っ込む。

<手順 2>
下記のファイルを、同じく"Greeting"と言う名前のフォルダに突っ込む。

mail23dec2022.txt
◯◯様、

いつも大変お世話になっております。
山田太郎です。
早いもので、本年も残りわずかとなり、年末のご挨拶をさせていただく時期となりました。

メールにて、恐縮ではございますが、年末のご挨拶とさせて頂きたいと思います。
良いお年をお迎えください。

山田太郎

<手順 3>
下記のコードを、同じく、"Greeting"フォルダに突っ込む。

year_end_23dec2022.scpt
set org to AppleScript's text item delimiters -- オリジナルの区切り文字を保存
set AppleScript's text item delimiters to "," -- 区切り文字を","に変更

set srcFile to ("/Users/testuser/Desktop/Greeting/recipient_list.csv") as text
set lns to paragraphs of (read srcFile as «class utf8»)

set theText to loadText("/Users/testuser/Desktop/Greeting/mail23dec2022.txt")

on loadText(theFile)
	try
		open for access theFile
		set theText to read theFile
	end try
	close access theFile
	return theText
end loadText

repeat with ln in lns
	
	set theList to every text item of ln -- 区切り文字で分解してリストを作成
	set theHonbun to (item 1 of theList) -- リストから宛先を取り出して本文を作成
	set theAddress to item 2 of theList -- リストからアドレスを取り出し
	
	-- display dialog theHonbun -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。) 
	-- display dialog theAddress -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。)
	-- display dialog theText -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。)
	--set theAttachmentFile to "MacintoshHD:Users:testuser:Desktop:Greeting:testPDF2022.pdf" -- 添付ファイル(testPDF2022.pdf)を添付する場合はコメントを外す。
	
	tell application "Microsoft Outlook"
		
		set theMessage to make new outgoing message at mail folder "Drafts" with properties {subject:theHonbun & "様、年末のご挨拶【海山商事、山田太郎】", content:theHonbun & " 様" & theText}
		
		-- tell theMessage to make new attachment with properties {file:theAttachmentFile as alias}
		--make new recipient with properties {email address:{address:"abc@gmail.com"}} at end of cc recipients of theMessage -- ccで誰かを入れたい場合はここに固定で入れる。
		make new recipient with properties {email address:{address:theAddress}} at end of to recipients of theMessage
		--move theMessage to mail folder "Drafts"
		send theMessage
		
	end tell
	
	
end repeat

set AppleScript's text item delimiters to org -- オリジナルの区切り文字に戻す

以上で終了。

<操作説明>
Greetingフォルダ内にある、”year_end_23dec2022.scpt”ファイルをダブルクリックする。プログラムが開くので、三角ボタンをクリックするだけ。
名称未設定4.png
以上で、300人超の顧客に個別メールを送信完了。
(プログラム開発時間30分。操作時間1秒。)

<注意>
上のプログラムでは、下記をコメント扱いしているので、一瞬で300人に送信可能です。
一つずつ確認して送信したいなら、コメントを外してください。(コメントアウトしてください。)

<上は、コメントがついている状態。>

-- display dialog theHonbun -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。) 
-- display dialog theAddress -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。)
-- display dialog theText -- 確認のため本文を表示したいなら、コメントを外す。(コメント状態だと、recipient_listに書かれたすべての人に一瞬で送信されます。)

そうすると、一件ずつ、お客様名、メールアドレス、メール本文を確認しながら、OKを押して処理をしてゆく形となります。
(慎重にやるなら、こちらでしょうが、今回は、他愛無い年末挨拶なので、そんなに神経質になる必要はない。)

2
1
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
2
1