LoginSignup
1
0

s-nailで外部SMTPサーバーを利用してメール送信

Last updated at Posted at 2023-05-19

mailとかmailxとかこれまで色々使って来ましたがRHEL9でs-nailを使うことにしました。DDNSでのメールサーバー運用は工数がかさみ割に合わないので、契約しているプロバイダのSMTPを使用してます。

外部送信SMTPサーバー: smtp.external
SMTP認証ポート: 587
SMTP認証ユーザーID: xxx@xxx.external
SMTP認証パスワード: xxx[xxx\xxx
From: from@xxx.external
To: to@yyy.zzz

以下備忘。

基本構文は以下。
s-nail -:/ -s "Subject" -S v15-compat -S mta=smtp://USER:PASS@smtp.external:PORT -S from=From@Address To@Address < MailBody

やってみる。

$ s-nail -:/ -s "Test Mail" -S v15-compat -S mta=smtp://xxx@xxx.external:xxx[xxx\xxx@smtp.external:587 -S from=from@xxx.external to@yyy.zzz < ./MailBody 
s-nail: Not URL percent encoded (use `urlcodec enc'): xxx[xxx\xxx
s-nail: *mta*: invalid or unsupported value: smtp://xxx@xxx.external:xxx[xxx\xxx@smtp.external:587
/home/user/dead.letter 8/188
s-nail: ... message not sent
$

percent encodeされてないよ、urlcodec encを使え、と言っている。
s-nailのman pageを確認。

:
:
On URL syntax and credential lookup
For accessing protocol-specific resources Uniform Resource Locators (URL, RFC 3986) have become
omnipresent. Here they are expected in a “normalized” variant, not used in data exchange, but
only meant as a compact, easy-to-use way of defining and representing information in a well-
known notation; as such they do not conform to any real standard. Optional parts are placed in
brackets ‘[]’, optional either because there also exist other ways to define the information, or
because the part is protocol specific. ‘/path’ for example is used by the [Option]al Maildir
folder type and the IMAP protocol, but not by POP3. If ‘USER’ and ‘PASSWORD’ are included in an
URL server specification, URL percent encoded (RFC 3986) forms are needed, generable with
urlcodec.

:
:
Raw data arguments for codec commands
A special set of commands, which all have the string “codec” in their name, like addrcodec,
shcodec, urlcodec, take raw string data as input, which means that the content of the command
input line is passed completely unexpanded and otherwise unchanged: like this the effect of the
actual codec is visible without any noise of possible shell quoting rules etc., i.e., the user
can input one-to-one the desired or questionable data. To gain a level of expansion, the entire
command line can be evaluated first, for example
:
:

うーむ、とりあえずやってみる。

$ echo 'urlcodec enc xxx@xxx.external' | s-nail -#
xxx%40xxx.external
$

お、意味が分かった。

$ echo 'urlcodec enc xxx[xxx\xxx' | s-nail -#
xxx%5Bxxx%5Cxxx
$

percent encodedのユーザー名とパスワードを入力してリトライ。

$ s-nail -:/ -s "Test Mail" -S v15-compat -S mta=smtp://xxx%40xxx.external:xxx%5Bxxx%5Cxxx@smtp.external:587 -S from=from@xxx.external to@yyy.zzz < ./MailBody 
$

無事メールが届きました。

//

1
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
1
0