LoginSignup
7
6

More than 5 years have passed since last update.

ArchLinux@RaspberryPiでGmail経由のメール送信

Last updated at Posted at 2014-02-11

自分用設定手順メモ。
下記のページを参考にしました。(何となくでしか理解していません)
http://linuxaria.com/pills/how-to-configure-postfix-as-smtp-relay-for-gmail-on-archlinux?lang=en

必要パッケージのインストール

pacman -Sy postfix ca-certificates

Postfix設定ファイルの編集

nano /etc/postfix/main.cf

以下を追記。
hostname, domainnameは読み替え部分です。
元々書いてある該当行のコメントを外して編集してもOKです。

/etc/postfix/main.cf
myhostname = hostname # your host name
mydomain = domainname # your domain name
myorigin = $myhostname
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 127.0.0.0/8

relayhost = [smtp.gmail.com]:587

header_checks = regexp:/etc/postfix/header_checks

smtp_generic_maps = hash:/etc/postfix/generic
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_enforce_tls = yes

disable_dns_lookups = yes

設定ファイル編集

Gmail認証設定

nano /etc/postfix/relay_password

以下の1行を書いてファイルを保存。

/etc/postfix/relay_passoword
[smtp.gmail.com]:587    youraccount@gmail.com:yourpassword

/etc/postfix/header_checks

nano /etc/postfix/header_checks

下記の行を追記。
hostname, domainname, youraccountは読み替え部分です。

/etc/postfix/header_checks
/^To:.*@hostname.localnet/ REDIRECT youraccount@gmail.com 
/^From:(.*@domainname[>]*)/ PREPEND Reply-To:$1

/etc/postfix/generic

nano /etc/postfix/generic

下記の行を追記。
例によってhostname, domainname, youraccountは読み替え部分です。

/etc/postfix/generic
root@domainname           youraccount@gmail.com
root@hostname.localnet    youraccount@gmail.com
user@hostname.localnet    youraccount@gmail.com

設定の反映等

次のコマンドを実行

postmap /etc/postfix/generic
postmap /etc/postfix/relay_password
cat /etc/ssl/certs/Equifax_Secure_CA.pem >/etc/postfix/cacert.pem

Postfix起動

systemctl start postfix

自動起動設定

systemctl enable postfix

テスト送信


echo "body of the message" | mail -r "youraccount@gmail.com" -s "TEST MAIL" to@email.com
7
6
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
7
6