18
18

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にopensslで接続してhtmlメールを送る

Posted at

GmailをSMTPサーバとして利用する方法です。

  • openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
    • -ign_eofがないと、以下のエラーでRCPT TO後に死ぬ

RENEGOTIATING
21874:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:/SourceCache/OpenSSL098/OpenSSL098-50/src/ssl/s3_pkt.c:543:

  • opensslでセッションを開始したあとの対話は以下のように進みます
EHLO localhost #ユーザー入力
250-mx.google.com at your service, [106.138.98.200]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
AUTH LOGIN #ユーザー入力
334 xxxxxxx
xxxxxxxxxxxxxxxxx #ユーザー入力、認証(user)
334 xxxxxxx
xxxxxxxxxxxxxxxxx #ユーザー入力、認証(pass)
235 2.7.0 Accepted
MAIL FROM: <xxx@gmail.com> #ユーザー入力
250 2.1.0 OK fe3sm63961472pbd.66 - gsmtp
RCPT TO: <xxxx@example.com> #ユーザー入力
250 2.1.5 OK fe3sm63961472pbd.66 - gsmtp
DATA #ユーザー入力
354  Go ahead fe3sm63961472pbd.66 - gsmtp
Subject: test_html #ユーザー入力
Mime-Version: 1.0; #ユーザー入力
Content-Type: text/html; charset="ISO-8859-1"; #ユーザー入力
Content-Transfer-Encoding: 7bit; #ユーザー入力

<!DOCTYPE HTML>
<html lang="ja-JP">
<body>
<h1>はろーはろー</h1>
</body>
<html>
.

はまったところ

以下を参考にしました

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?