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?

More than 5 years have passed since last update.

gmail経由でメールを投げる

Last updated at Posted at 2013-07-02

Gmailでメールを投げる

BackupShellみたいな夜間バッチが夜中にブンまわって実行結果をメールでよこせ。
SMTPサーバー?そんなもの入れられん!とかそんな時。
適当にGmailで捨てアカ取ってそこを踏み台にすればいいんじゃね?
※ただしPerlは入れる

メールを投げるスクリプト
authorize="`perl -MMIME::Base64 -e 'print encode_base64("\000******\@*******\000**********")'`"
    (
      sleep 3
      echo "EHLO `hostname`" 
      sleep 3
      echo "AUTH PLAIN ${authorize}" 
      sleep 3
      echo "MAIL FROM: <${mail_user}>" 
      sleep 3
      echo "rCPT TO: <${to}>" 
      sleep 3
      echo "DATA" 
      sleep 3
      (
        echo "Subject: ***************" 
        echo "From: ${mail_user}" 
        echo "To: ${to}" 
        echo "" 
        echo "message: ${error_msg}" 
        echo "hostname: `hostname`" 
        echo "filename: ${date}_daily" 
        echo "date: `date +%Y/%m/%d` `date +%H:%M:%S`"              
        echo "." 
      ) | perl -pe's/(?<!\r)\n/\r\n/'
      sleep 3
      echo "QUIT" 
    ) | openssl s_client -connect smtp.gmail.com:465

※ユーザー名・パスワードは先頭に「000」をつけないと認証ではじかれる。
※メンテ性を考えると、あらかじめ適当な変数に暗号化した文字列突っ込んどきゃいいんじゃね?って思ってやったらできなかった。どうやら暗号化ロジックそのものを渡してやらないといけないらしい。なんで?

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?