Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

Go - メール送信

go-gomail/gomailというのがスター1000個以上あるので使ってみます。Ubuntu16.04にpostfixを入れてGmailで送信されるように設定してます。

とりあえず下記で送信されました。

main.go
package main

import (
    "gopkg.in/gomail.v2"
)

func main() {
    m := gomail.NewMessage()
    m.SetHeader("From", "from@example.com")
    m.SetHeader("To", "to@example.com")
    m.SetHeader("Subject", "Hello!")
    m.SetBody("text/plain", "Hello!")

    d := gomail.Dialer{Host: "localhost", Port: 25}
    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }
}

添付とか、HTMLメールとかもできるみたいなので、今度やってみます。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
6
Help us understand the problem. What are the problem?