Created
November 4, 2009 19:09
-
-
Save muddana/226298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filename = "test_mail.rb" | |
file = File.new("./"+filename, "r") | |
filecontent = "" | |
file.each do |line| | |
filecontent << line | |
end | |
encodedcontent = [filecontent].pack("m") # base64 | |
marker = "TESTBOUNDARY" | |
body = <<MESSAGE_BODY | |
Hi ALL, | |
Regards, | |
Mr. XYZ. | |
p.s: i have sent this mail using some ruby script :) | |
MESSAGE_BODY | |
message = <<MESSAGE | |
From: [email protected] | |
To: [email protected] | |
Subject: Sending Mails works | |
MIME-Version: 1.0 | |
Content-Type: multipart/mixed; boundary=#{marker} | |
--#{marker} | |
Content-Type: text/plain | |
Content-Transfer-Encoding:8bit | |
#{body} | |
--#{marker} | |
Content-Type: multipart/mixed; name=\"#{filename}\" | |
Content-Transfer-Encoding:base64 | |
Content-Disposition: attachment; filename="#{filename}" | |
#{encodedcontent} | |
--#{marker}-- | |
MESSAGE | |
#!/usr/bin/env ruby | |
require 'net/smtp' | |
Net::SMTP.start( | |
'smtp.xyz.com', | |
25, | |
'xyz.com' | |
) do |smtp| | |
smtp.send_message( | |
message, | |
'[email protected]', | |
[ ' [email protected]'] | |
) | |
smtp.finish | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment