Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/37c7f4c429208111dda3 to your computer and use it in GitHub Desktop.
Save yaasita/37c7f4c429208111dda3 to your computer and use it in GitHub Desktop.
diff --git a/bin/ymst.sh b/bin/ymst.sh
index d3e6a6f..758b3c4 100755
--- a/bin/ymst.sh
+++ b/bin/ymst.sh
@@ -1,6 +1,9 @@
#!/bin/bash
set -e
cd `dirname $0`
+if [ "$CLIENT_ADDRESS" != "192.168.33.1" ] || [ "$SENDER" != "from@hoge.example.com" ] ;then
+ exit
+fi
mailfile=`mktemp`
cat - > $mailfile
ruby send.rb $mailfile
diff --git a/bin/send.rb b/bin/send.rb
index c712c84..0a0e6a8 100755
--- a/bin/send.rb
+++ b/bin/send.rb
@@ -18,7 +18,7 @@ def send_mail_data(filename)
end
@yaml[envelope_to].each do |member|
- IO.popen("/usr/sbin/sendmail -f #{ENV['SENDER']} #{member}","w") do |io|
+ IO.popen("/usr/sbin/sendmail -f info@example.ml #{member}","w") do |io|
io.puts send_mail_data(mail_file)
end
end
diff --git a/bin/send.rb b/bin/send.rb
index c712c84..bdeb8b9 100755
--- a/bin/send.rb
+++ b/bin/send.rb
@@ -14,7 +14,7 @@ end
def send_mail_data(filename)
mail = Mail.read(filename)
# edit mail data
- return mail.to_s
+ return mail.to_s.gsub(/^received.*\n|x-original-to.*\n|delivered-to.*\n/i,"")
end
@yaml[envelope_to].each do |member|
#!/bin/bash
set -e
cd `dirname $0`
if [ "$ORIGINAL_RECIPIENT" = "mltest1@ml.example.com" ];then
exit;
fi
mailfile=`mktemp`
cat - > $mailfile
ruby send.rb $mailfile
rm $mailfile
#!/bin/bash
set -e
cd `dirname $0`
if [ "$ORIGINAL_RECIPIENT" = "mltest1@ml.example.com" ];then
echo "address not found" 1>&2
exit 69
fi
mailfile=`mktemp`
cat - > $mailfile
ruby send.rb $mailfile
rm $mailfile
#!/bin/bash
set -e
cd `dirname $0`
if [ ! -e ../mail.yml ];then
exit 75
fi
mailfile=`mktemp`
cat - > $mailfile
ruby send.rb $mailfile
rm $mailfile
diff --git a/bin/send.rb b/bin/send.rb
index c712c84..e15e492 100755
--- a/bin/send.rb
+++ b/bin/send.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'yaml'
require 'mail'
+require 'digest/sha1'
Dir.chdir(File.dirname(File.expand_path(__FILE__)) + "/..")
@@ -11,14 +12,15 @@ File.open("mail.yml") do |f|
@yaml = YAML.load(f)
end
-def send_mail_data(filename)
+def send_mail_data(filename,member)
mail = Mail.read(filename)
# edit mail data
+ mail.body = mail.body.to_s.gsub(/^http.*\//,"\\&?q=#{Digest::SHA1.hexdigest(member)}")
return mail.to_s
end
@yaml[envelope_to].each do |member|
IO.popen("/usr/sbin/sendmail -f #{ENV['SENDER']} #{member}","w") do |io|
- io.puts send_mail_data(mail_file)
+ io.puts send_mail_data(mail_file,member)
end
end
diff --git a/postfix/main.cf b/postfix/main.cf
index 9b2f712..5c6c76c 100644
--- a/postfix/main.cf
+++ b/postfix/main.cf
@@ -35,7 +35,11 @@ alias_database = hash:/etc/aliases
mydestination = localdomain, localhost
virtual_alias_maps = regexp:/etc/postfix/aliases.reg
virtual_alias_domains = ml.example.com
-relayhost =
+relayhost = [smtp.gmail.com]:587
+smtp_sasl_auth_enable = yes
+smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
+smtp_sasl_tls_security_options = noanonymous
+smtp_sasl_mechanism_filter = plain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment