Module: MailMCP::MailBuilder
- Defined in:
- lib/mail_mcp/mail_builder.rb
Class Method Summary collapse
- .attach_from_url(mail, url) ⇒ Object
- .build(from:, to:, subject:, text_body:, cc: nil, bcc: nil, html_body: nil, attachment_urls: []) ⇒ Object
Class Method Details
.attach_from_url(mail, url) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/mail_mcp/mail_builder.rb', line 33 def attach_from_url(mail, url) URI.open(url) do |f| filename = File.basename(URI.parse(url).path) mail.[filename] = { content: f.read, mime_type: f.content_type } end rescue StandardError => e raise "Failed to fetch attachment from #{url}: #{e.}" end |
.build(from:, to:, subject:, text_body:, cc: nil, bcc: nil, html_body: nil, attachment_urls: []) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mail_mcp/mail_builder.rb', line 8 def build(from:, to:, subject:, text_body:, cc: nil, bcc: nil, html_body: nil, attachment_urls: []) mail = Mail.new mail.from = from mail.to = to mail.subject = subject mail.cc = cc if cc mail.bcc = bcc if bcc if html_body mail.html_part = Mail::Part.new do content_type "text/html charset=UTF-8" body html_body end mail.text_part = Mail::Part.new do content_type "text/plain charset=UTF-8" body text_body end else mail.body = text_body end .each { |url| attach_from_url(mail, url) } mail end |