Skip to content

Instantly share code, notes, and snippets.

@romeuhcf
Created October 8, 2015 12:07
Show Gist options
  • Save romeuhcf/cd17edd1dde6bd76f411 to your computer and use it in GitHub Desktop.
Save romeuhcf/cd17edd1dde6bd76f411 to your computer and use it in GitHub Desktop.
Parte do sistema de envio referente ao envio de email para fornecedor.
...
mail = Mail.new do
self.content_transfer_encoding = 'quoted-printable'
subject envio_mono.assunto
from hdr.sender
to envio_mono.mail
html_part do
self.content_transfer_encoding = 'quoted-printable'
content_type "text/html; charset=#{Encoding.default_internal.to_s}"
body premailer.to_inline_css
end
encoding = Mail::Encodings::Base64
data = Premailer.new(File.read_recode(html_file), warn_level: Premailer::Warnings::SAFE, with_html_string: true).to_inline_css
grava_para_analise(data, 'htmlrecode') # salva em disco para verificarmos a existencia de caracteres estranhos
self.attachments['Para Imprimir.html']= { :data=> encoding.encode(data), :encoding => encoding::NAME }
end
message = mail.to_s
unique_id = transmission_request.unique_id
xsmtplw = "x-smtplw: #{unique_id}"
replyto = "Reply-To: <#{original_sender_address}>"
message = [xsmtplw, replyto, message].join("\r\n")
result = Net::SMTP.start('smtplw.com.br', 587, sender_domain, user, pass, :login) do |smtp|
smtp.send_message message, sender, [recipient]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment