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?

More than 1 year has passed since last update.

UWSC: Gmailでメール送信

Last updated at Posted at 2020-06-03

参考サイトをほぼそのまま使用させてもらってます。
ありがとうございます。

Gmailで送信しようとするとセキュリティを緩める必要が出てきます。
本メールアドレスではなく送信専用のgoogleアカウントを取ったほうがいいでしょう。

  • アプリパスワードの設定

 SMTP認証で使用する{password}が必要です。
 Googleアカウント内で設定します。

参考サイト:アプリパスワード

Gmailから送信
sendMail("{送信メールアドレス}", "{受信メールアドレス}", "{タイトル}", "{本文}")

PROCEDURE SendMail(mailfrom, mailto, subject, body)
	smtpserver = "smtp.gmail.com"	//SMTP Server設定
	smtpserverport = 465

	Dim objEmail = CreateOleObj("CDO.Message")
	objEmail.From = mailfrom
	objEmail.To = mailto
	objEmail.Subject = subject
	objEmail.Textbody = body

	schemas = "http://schemas.microsoft.com/cdo/configuration/"
	objEmail.Configuration.Fields.Item(schemas + "sendusing") = 2
	objEmail.Configuration.Fields.Item(schemas + "smtpserver") =  smtpserver
	objEmail.Configuration.Fields.Item(schemas + "smtpserverport") = smtpserverport

	//SMTP認証。
	objEmail.Configuration.Fields.Item(schemas + "smtpauthenticate") = true
	objEmail.Configuration.Fields.Item(schemas + "sendusername") = mailfrom
	objEmail.Configuration.Fields.Item(schemas + "sendpassword") = "{password}"

	//SSL接続。
	objEmail.Configuration.Fields.Item(schemas + "smtpusessl") = true
	objEmail.Configuration.Fields.Update
	COM_ERR_IGN   //ネット回線が切断されている時にメールを送信するとエラーなるのを防止
	objEmail.Send
	COM_ERR_RET
FEND
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?