lib/gmail.rb in alexmchale-gmail-client-0.2.1 vs lib/gmail.rb in alexmchale-gmail-client-0.3.0

- old
+ new

@@ -40,11 +40,11 @@ attachments = @attachments.map do |attachment| "--#{boundary}\r\n" + "Content-Type: #{attachment[:type]}; name=\"#{attachment[:name]}\"\r\n" + "Content-Disposition: attachment; filename=\"#{attachment[:name]}\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + - "Content-ID: <#{attachment[:name]}>\r\n" + + "Content-ID: <#{attachment[:name]}>\r\n" + "\r\n" + Base64.encode64(attachment[:data]) end.compact.join "Date: #{Time.now.to_s}\r\n" + @@ -67,25 +67,22 @@ "From: #{@username}\r\n" + "To: #{@to}\r\n" + "Subject: #{@subject}\r\n" + "Content-Type: #{@body_type}\r\n" + "\r\n" + - "#{@body}\r\n" + - "\r\n.\r\n" + @body end end def dispatch Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', @username, @password, :plain) do |smtp| smtp.send_message compose, @username, @to end end - def send(to, subject, body, content_type = 'text/plan') - Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', @username, @password, :plain) do |smtp| - msg = "From: #{@username}\r\nTo: #{to}\r\nSubject: #{subject}\r\nContent-Type: #{content_type}\r\n\r\n#{body}" - smtp.send_message msg, @username, to - end + def send(to, subject, body, content_type = 'text/plain') + start to, subject, body, content_type + dispatch end end # Net::SMTP monkeypatching was taken from: # http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html