メール送信スクリプト

perl

#!/usr/bin/perl

use Encode;
use Net::SMTP;

$smtp_server = '';
$port = 25;
$timeout = 2;
$user = '';
$password = '';
$from = '';
$to = ''; #カンマ区切りで複数指定可
@to = split(',',$to);
$subject = "";
$body = "";

#euc-jpからjisに変換
Encode::from_to($subject,'euc-jp','jis');
Encode::from_to($body,'euc-jp','jis');

$smtp = Net::SMTP->new($smtp_server,Port=>$port,Timeout=>$timeout);
#$smtp->auth($user,$password);
$smtp->mail($from);
$smtp->to(@to);
$smtp->data;
$smtp->datasend("From: $from\n");
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("Content-Type: text/plain; charset=\"iso-2022-jp\"\n");
$smtp->datasend("$body\n");
$smtp->dataend;
$smtp->quit;

参照したURL:
http://g-chan.dip.jp/square/archives/2009/05/perl_netsmtp.html

ruby

mail

#!/usr/bin/env ruby
require 'mail'

mail = Mail.new do
  from     'me@test.lindsaar.net'
  to       'you@test.lindsaar.net'
  subject  'Here is the image you wanted'
  body     File.read('body.txt')
  add_file :filename => 'somefile.png', :content => File.read('/somefile.png')
end

mail.charset = 'utf-8'
mail.delivery_method :smtp, address: "localhost", port: 1025
mail.deliver

参照したURL:https://github.com/mikel/mail


net/smtp

#!/usr/bin/ruby

require 'net/smtp'
require 'kconv'

smtp_server = ''
port = 25
helo_domain = ''
account = ''
password = ''
authtype = '' # plain, cram_md5
from = ''
to = ['','',...]
subject = "".tojis
body = "".tojis

Net::SMTP.start smtp_server,port,helo_domain,account,password,authtype){|smtp|
  smtp.ready(from,to){|f|
    f.puts 'From:' + from
    f.puts 'To:' + to.join(',')
    f.puts 'Subject:' + subject
    f.puts
    f.puts body
  }
}

参照したURL:
http://www.ruby-lang.org/ja/old-man/html/net_smtp.html

bourne shell(telnet使用)

#!/bin/sh
(
echo "helo <ドメイン名>"; sleep 1
echo "mail from: <送信元アドレス>"; sleep 1
echo "rcpt to: <送信先アドレス>"; sleep 1
echo "data"; sleep 1
echo "subject: <件名>"; sleep 1
echo "to: <送信先アドレス>"; sleep 1
echo "本文";
echo "."; sleep 1
echo "quit"
) | telnet <メールサーバのアドレス> 25