[Perl]メールで控える、コマンドラインからメモ
つかいどころが微妙だけど、ぽこぽことメールでメモしたくて用意したスクリプト。
どちらかというと、Perlの習作に何かを作りたいというほうがメイン。
#!/usr/bin/env perl use strict; use warnings; use Jcode; use File::Basename; use Net::SMTP; my $SMTP_HOST = 'smtp.example.com'; my $SMTP_PORT = '25'; my $FROM = 'foo@example.com'; my $to = basename(__FILE__); print "<SUBJECT>\n"; my $subject = <STDIN>; chomp $subject; print "<BODY>\n"; my $body = <STDIN>; chomp $body; my %headers = ( 'From' => jcode($FROM)->mime_encode, 'To' => jcode($to)->mime_encode, 'Subject' => jcode($subject)->mime_encode, 'MIME-Version' => '1.0', 'Content-type' => 'text/plain; charset=ISO-2022-JP', 'Content-Transfer-Encoding' => '7bit', ); my $header = ''; foreach my $k (keys %headers) { $header .= "$k: $headers{$k}\n"; } my $contents = jcode($body)->jis; my $smtp = Net::SMTP->new($SMTP_HOST, Port => $SMTP_PORT, Timeout => 30); $smtp->mail($FROM); $smtp->to($to); $smtp->data(); $smtp->datasend($header); $smtp->datasend("\n"); $smtp->datasend($contents); $smtp->dataend(); $smtp->quit; my $message = sprintf "sent the mail, %s to %s.\n", $FROM, $to; print $message; __END__
$ ln -s mail_to.sh hoge\@example.com $ hoge\@example.com <SUBJECT> ちょっとした <BODY> メモをメールする sent the mail, foo@example.com to hoge@example.com.