How to add mime module to sent email ruby

Hi
I am looking in google for long time about how to sent email with inline
image. and got this site

http://rubydoc.info/gems/mime/frames

i have installed gem install mime
its installed
but dont understand how to include MIME module in the code …

“The following examples imply that the MIME module is included.”

i am trying

require ‘rubygems’
require ‘mime’
msg = Message.new # creates a blank message with
date and message ID headers
msg.date = (Time.now - 3600).rfc2822 # specify a different date
msg.subject = ‘This is important’
msg.headers.add(‘X-Priority’, ‘high’) # custom header

msg.body = TextMedia.new(‘hello, it is me!’)

The following snippets are equivalent to the previous line.

msg.body = “\r\nhello, it is me!”

msg.header.add(‘Content-Type’, ‘text/plain; charset=us-ascii’)

–OR–

msg.body = "Content-Type: text/plain;

charset=us-ascii\r\n\r\nhello, it is me!"

msg.to = {
[email protected]’ => Fosiul, # no name display
[email protected]’ => ‘Fosiul’,
[email protected]’ => ‘Fosiul’,
}
msg.from = {
[email protected]’ => ‘Boss Man’
}

msg.to_s # ready to be sent via SMTP

but

i get "uninitialized constant Message (NameError) "

problem is, how to refer that in the script ?

thanks

Am 06.10.2012 14:46, schrieb Ferdous ara:

“The following examples imply that the MIME module is included.”

In Ruby you can include a module into your own class,
but you probably would not want to do that.

i am trying

require ‘rubygems’
require ‘mime’
msg = Message.new

i get "uninitialized constant Message (NameError) "

The Message class is part of the MIME module, try

msg = MIME::Message.new

Hi thanks

thats work but then i dont think it does sent anything

dont i have to define smtp ??

becase end of the code its saying

msg.to_s # ready to be sent via SMTP

where is the smtp code ??

Am 06.10.2012 16:50, schrieb Ferdous ara:

msg.to_s # ready to be sent via SMTP

where is the smtp code ??

Yes, it is only “ready to be sent”…

HI thanks

then how will i sent email ??

will it work with net/smtp module ??

yes its works with net/smtp

This is not a Ruby question, it’s about MIME.

For information about how to format a MIME mail with HTML and inline
images, see RFC 2387 and RFC 2392. RFC 2392 has an example of exactly
this:

“The following message contains an HTML body part that refers to an
image contained in another body part. Both body parts are contained
in a Multipart/Related MIME entity. The HTML IMG tag contains a
cidurl which points to the image.”

same problem if i use net/smtp … image does not work as inline …

Sorry, posted reply to wrong thread :frowning:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs