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

Perl: Starttls でメールの送信

Last updated at Posted at 2020-07-06

こちらと同じことを Node.js で行いました。
Python3: Starttls でメールの送信
Node.js: Starttls でメールの送信
hi-ho.ne.jp で試しました。

hi-ho.pl
# ! /usr/bin/perl
#
#	hi-ho.pl
#
#					Jul/06/2020
#
# ----------------------------------------------------------------
use Dotenv;
use Net::SMTP;
#
print STDERR "*** start ***\n";
#
my $env = Dotenv->parse('.env');
print STDERR %$env{'SERVER'} . "\n";
print STDERR %$env{'PORT'} . "\n";
#
my $mailhost = %$env{'SERVER'};
my $mailport = %$env{'PORT'};
my $mail_username = %$env{'FROM'};
my $mail_password = %$env{'PASSWORD'};
my $to_mail = %$env{'TO'};
my $from_mail = %$env{'FROM'};
my $smtp = Net::SMTP->new($mailhost, Port => $mailport);
#
$smtp->auth($mail_username, $mail_password);
$smtp->mail($from_mail);
$smtp->to($to_mail);
$smtp->data();
$smtp->datasend("From: $from_mail\n");
$smtp->datasend("To: $to_mail\n");
$smtp->datasend("Subject: Hello Jul/06/2020 AM 10:46\n");
$smtp->datasend("\n");
$smtp->datasend("Hello Everybody\n");
$smtp->datasend("おはようございます。\n");
$smtp->datasend("雨が降っています。\n");
$smtp->quit;
#
print STDERR "*** end ***\n";
#
# ----------------------------------------------------------------
.env
SERVER = 'hi-ho.mose-mail.jp'
PORT = 587
USR = '****@hi-ho.ne.jp'
PASSWORD = '****'
FROM = '****@hi-ho.ne.jp'
TO = 'sample@example.com'

実行結果

$ ./hi-ho.pl 
*** start ***
hi-ho.mose-mail.jp
587
*** end ***

次のバージョンで確認しました。

$ perl --version

This is perl 5, version 30, subversion 3 (v5.30.3) built for x86_64-linux-gnu-thread-multi

Dotenv のインストール方法

sudo apt install cpanminus
sudo cpanm Dotenv
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?