Img src while sending email ruby cgi

Hi
I am sending email by ruby cgi.
Sending is fine by html

but when i am trying to insert a image , it does not work… wondering
what i am doing wrong

here is the code :

message = <<MESSAGE_END
From:test user [email protected]
To: testuser [email protected]
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test

This is an e-mail message to be sent in HTML format

bay1.gif

MESSAGE_END

Net::SMTP.start(‘smtp.myemail.com’) do |smtp|
smtp.send_message message, ‘[email protected]’,
'[email protected]
end

email is going. but image is not attaching …

Can any one please help me .

Am 06.10.2012 00:10, schrieb Ferdous ara:

message = <<MESSAGE_END
MESSAGE_END

Can any one please help me .

You are not sending an email with an attached image,
you are only sending an email in HTML format,
which happens to contain some link.

I have never used Net::SMTP, so I can not tell you
how you would actually attach an image to an email.
Try searching for ‘ruby net smtp attachment’ or so…

Hi
Instead of attachment, Can i not imbedded the image ??

if i do attachment, Then it will sent as Attachment

but what i am trying to do is, the image will be seen in body of the
Email rather then attachment.

How will i do that ??

Thanks

Am 06.10.2012 00:45, schrieb Ferdous ara:

Thanks

you could for example

  • link to an image that is available through the internet
  • embed the image into the html (there are tutorials on how to do this)

On 6/10/2012, at 11:45 AM, Ferdous ara wrote:

Hi
Instead of attachment, Can i not imbedded the image ??

if i do attachment, Then it will sent as Attachment

but what i am trying to do is, the image will be seen in body of the
Email rather then attachment.

Sending images, or other non-text data, in an email has to be done as an
attachment. The difference is whether it is an inline attachment or
not. You want an inline attachment.

Sending emails with attachments is way more complicated than what you
have tried. Do a search for multipart email format and inline
attachments.

Henry

Hi
I am found this from this link

http://www.ruby-forum.com/topic/1159192

So i have done this

require ‘net/smtp’
require ‘fileutils’
require ‘rubygems’
require ‘base64’

fn = ‘bay1.gif’
src = “#{Base64.encode64(File.read(fn))}”
#new_tag = “

message = <<MESSAGE_END
From:test user [email protected]
To: testuser [email protected]
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test

This is an e-mail message to be sent in HTML format

bay1.gif

MESSAGE_END

Net::SMTP.start(‘smtp.myemail.com’) do |smtp|
smtp.send_message message, ‘[email protected]’,
'[email protected]
end

but still now luck …
Please give me little bit more light

ok to make this same as that link
i have done this

require ‘net/smtp’
require ‘fileutils’
require ‘rubygems’
require ‘base64’

fn = ‘test.png’
src = “data:image/png;base64,#{Base64.encode64(File.read(fn))}”

message = <<MESSAGE_END
From:test user [email protected]
To: testuser [email protected]
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test

This is an e-mail message to be sent in HTML format

test.png

MESSAGE_END

Net::SMTP.start(‘smtp.myemail.com’) do |smtp|
smtp.send_message message, ‘[email protected]’,
'[email protected]
end

still now luck

Please help me with this

Bartosz Dziewoński wrote in post #1078806:

What do you mean “no luck”? Is the message sent and received, but

Hi the email is coming, no error in code
but there is not image,

i can see the box, with alt ‘test.png’ in the email

but i dont see the image …

What do you mean “no luck”? Is the message sent and received, but
without the image? Does the code crash? Does it not arrive at all?
Maybe it’s rejected by a spam filter?

– Matma R.

Am 06.10.2012 12:28, schrieb Ferdous ara:

but i dont see the image …
you could try puts message instead of sending it.
is the image included in the output string?

did you try saving the HTML part of the message
into a file and open it with a browser?

unknown wrote in post #1078810:

Am 06.10.2012 12:28, schrieb Ferdous ara:

but i dont see the image …
you could try puts message instead of sending it.
is the image included in the output string?

Sorry did not understand what you meant…

did you try saving the HTML part of the message
into a file and open it with a browser?

how you want me to save this in to html ?? by using ruby cgi ??

also i found this

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

i have install gem install mime

but dont understand. how to call this

require ‘rubygems’
require ‘mime’

i am trying “Simple text/plain RFC822 email”

and running the script
it saying

uninitialized constant Message (NameError)

question is, how will call this ?? (require ‘mime’) it does not work
this way …

i am looking in net for long time … please some one help me

Am 06.10.2012 12:45, schrieb Ferdous ara:

unknown wrote in post #1078810:

Am 06.10.2012 12:28, schrieb Ferdous ara:

but i dont see the image …
you could try puts message instead of sending it.
is the image included in the output string?

Sorry did not understand what you meant…

First, look at the source code of the email you received.
If the image is embedded but not displayed, it could be
a problem with your email program.

If the image is not embedded in the first place you have to
poke into the code and try to figure out what is going on…

The simplest way to debug some code is including puts statements
to display the values of your variables, like src, message.

did you try saving the HTML part of the message
into a file and open it with a browser?

how you want me to save this in to html ?? by using ruby cgi ??

This has nothing to do with cgi. Just change your program like shown
below and run it. This saves the HTML snippet of your message to a file
(instead of sending it). Then open the created HTML file in your
browser. Does it display your image? (In my case it does.)

message = <<MESSAGE_END

test.png

MESSAGE_END

File.open(‘test.html’, ‘w’) {|f| f.puts message }

Am 06.10.2012 15:09, schrieb Ferdous ara:

HI yes
i can see in html format

Do you see the same in the source code of your received email?

no
i was checking in gmail .

but i dont see the 64 bit code …

HI yes
i can see in html format

http://fosiul.com/test.html

cat test.html

From: Fosiul alam [email protected]
To: Fosiul A. [email protected]
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test

This is an e-mail message to be sent in HTML format