11
11

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 5 years have passed since last update.

Raspberry PiのIPアドレスを自動でメールに送信する(CNS編)

Last updated at Posted at 2016-07-17

#SFC生にとってラズパイは無くてはならない

だがCNSでデモしようとするとIPアドレスの確認がめんどい。
自動的ににIPアドレスをメールで送ってほしい。

##sSMTPを導入

sudo apt-get install sSMTP

##sSMTPを設定する
sudo nano /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=hogehoge@sfc.keio.ac.jp

# 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=smtp.sfc.keio.ac.jp:465

# Where will the mail seem to come from?
rewriteDomain=sfc.keio.ac.jp

# The full hostname
hostname=hoge

# 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

AuthUser=ログイン名
AuthPass=メールパスワード
UseTLS=YES

##ネットワークが上がったら自動でメールを送るスクリプトを書く
sudo nano /etc/network/if-up.d/ipmail

#! /bin/bash
sleep 30s
ip addr | mail -s "ip is..." "送りたいアドレス@sfc.keio.ac.jp"

30秒くらいスリープを入れないと、ネットが上がってもIPアドレスが取れてなかったりして送信に失敗するので。

11
11
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
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?