Skip to content

Added code to check for existence of html or text body when attachments ... #30

Merged
merged 1 commit into from Jan 16, 2013
View
5 lib/aws/ses/send_email.rb
@@ -96,8 +96,9 @@ def send_email(options = {})
# @option args [String] :to alias for :destinations
# @return [Response]
def send_raw_email(mail, args = {})
- message = mail.is_a?(Hash) ? Mail.new(mail).to_s : mail.to_s
- package = { 'RawMessage.Data' => Base64::encode64(message) }
+ message = mail.is_a?(Hash) ? Mail.new(mail) : mail
+ raise ArgumentError, "Attachment provided without message body" if message.has_attachments? && message.text_part.nil? && message.html_part.nil?
+ package = { 'RawMessage.Data' => Base64::encode64(message.to_s) }
package['Source'] = args[:from] if args[:from]
package['Source'] = args[:source] if args[:source]
if args[:destinations]
View
6 test/helper.rb
@@ -54,3 +54,9 @@ def generate_base
Base.new(:access_key_id=>'123', :secret_access_key=>'abc')
end
end
+
+# Deals w/ http://github.com/thoughtbot/shoulda/issues/issue/117, see
+# http://stackoverflow.com/questions/3657972/nameerror-uninitialized-constant-testunitassertionfailederror-when-upgradin
+unless defined?(Test::Unit::AssertionFailedError)
+ Test::Unit::AssertionFailedError = ActiveSupport::TestCase::Assertion
+end
View
20 test/send_email_test.rb
@@ -46,6 +46,24 @@ class SendEmailTest < Test::Unit::TestCase
assert_equal 'xyz-123', result.request_id
end
+ should 'throw ArgumentException when attachment supplied without a body' do
+ #mock_connection(@base, :body => %{
+ # <SendRawEmailResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
+ # <SendRawEmailResult>
+ # <MessageId>abc-123</MessageId>
+ # </SendRawEmailResult>
+ # <ResponseMetadata>
+ # <RequestId>xyz-123</RequestId>
+ # </ResponseMetadata>
+ # </SendRawEmailResponse>
+ #})
+ message = Mail.new({:from => 'jon@example.com', :to => 'dave@example.com', :subject => 'Subject1'})
+ message.attachments['foo'] = { :mime_type => 'application/csv', :content => '1,2,3' }
+ assert_raise ArgumentError do
+ result = @base.send_raw_email message
+ end
+ end
+
should 'send a raw e-mail with a hash object' do
mock_connection(@base, :body => %{
<SendRawEmailResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
@@ -64,4 +82,4 @@ class SendEmailTest < Test::Unit::TestCase
assert_equal 'xyz-123', result.request_id
end
end
-end
+end
Something went wrong with that request. Please try again.