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?

コード

package main

import (
	"fmt"
	"net/smtp"
)

func main() {
	// SMTPサーバーの設定
	smtpHost := "smtp.gmail.com"
	smtpPort := "587"
	smtpUser := "ここに自分のGmailアカウント名@gmail.com"
	smtpPass := "ここにSMTP送信用パスワード"

	// 送信者と受信者のメールアドレス
	from := "ここに自分のGmailアカウント名@gmail.com"
	to := "ここに自分のGmailアカウント名@gmail.com"

	// メールの件名と本文
	subject := "【TEST】件名が入ります"
	body := "本文です。"

	// メールのメッセージ
	message := []byte("To: " + to + "\n" + "Subject: " + subject + "\n\n" + body)

	// SMTP認証情報
	auth := smtp.PlainAuth("", smtpUser, smtpPass, smtpHost)

	// メール送信
	err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{to}, message)
	if err != nil {
		fmt.Println("エラー:", err)
		return
	}

	fmt.Println("送信成功!")
}

動かしてみる

go run main.go
送信成功!

参考

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?