Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/mail/network/delivery_methods/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def initialize(values)
# The from and to attributes are optional. If not set, they are retrieve from the Message.
def deliver!(mail)
smtp_from, smtp_to, message = check_delivery_params(mail)
message = dot_stuff(message)

smtp = Net::SMTP.new(settings[:address], settings[:port])
if settings[:tls] || settings[:ssl]
Expand All @@ -107,7 +108,7 @@ def deliver!(mail)
smtp.enable_starttls_auto(ssl_context)
end
end

response = nil
smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp_obj|
response = smtp_obj.sendmail(message, smtp_from, smtp_to)
Expand All @@ -122,6 +123,10 @@ def deliver!(mail)


private

def dot_stuff(message)
message.gsub(/(\r\n\.)(\r\n|$)/, "\\1.\\2")
end

# Allow SSL context to be configured via settings, for Ruby >= 1.9
# Just returns openssl verify mode for Ruby 1.8.x
Expand Down
20 changes: 20 additions & 0 deletions spec/mail/network/delivery_methods/smtp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
end

describe "general usage" do

it "properly dot-stuff emails" do

mail = Mail.deliver do
from 'roger@moore.com'
to 'marcel@amont.com'
subject 'invalid RFC2822'
body "this is a test\n.\nonly a test\n."

smtp_envelope_from 'smtp_from'
smtp_envelope_to 'smtp_to'
end

MockSMTP.deliveries[0][0].should include "\r\n..\r\n"
MockSMTP.deliveries[0][0].should =~ %r{\r\n..$}
MockSMTP.deliveries[0][0].should eq Mail::SMTP.new({}).send :dot_stuff, mail.encoded
MockSMTP.deliveries[0][1].should eq 'smtp_from'
MockSMTP.deliveries[0][2].should eq %w(smtp_to)

end

it "should send emails from given settings" do

Expand Down