ターミナルからメールを送信する

Category :

    SSMTPをインストール

    sudo apt install ssmtp

    SSMTPの設定

    次に/etc/ssmtp/ssmtp.confの設定を行います。

    #
    # Config file for sSMTP sendmail
    #
    # The person who gets all mail for userids < 1000
    # Make this empty to disable rewriting.
    #root=postmaster
    root=myemail@hoge.com
    # The place where the mail goes. The actual machine name is required no
    # MX records are consulted. Commonly mailhosts are named mail.domain.com
    #mailhub=mail
    mailhub=smtp.hoge.com:587
    AuthUser=myemail@hoge.com
    AuthPass=*****
    UseTLS=YES
    UseSTARTTLS=YES
    # Where will the mail seem to come from?
    #rewriteDomain=
    rewriteDomain=hoge.com
    # The full hostname
    #hostname=
    hostname=MyServer
    # Are users allowed to set their own From: address?
    # YES - Allow the user to specify their own From: address
    # NO - Use the system generated From: address
    FromLineOverride=YES

    送信テスト

    テスト用のメールを作成します。

    $ vim testmail.txt
    testmail.txt
    To: recieve@hoge.com
    From: myemail@hoge.com
    Subject: ssmtp test
    Test message.

    作成したテストメールを送信します。

    $ sendmail -t < testmail.txt
    もしくは
    $ ssmtp recieve@hoge.com < testmail.txt

    送信先に指定したメールアドレスに作成したメッセージが届いていれば成功です。

    TOP
    © 2021 uichi