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 <test@test.com>
To: testuser <test@test.com>
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

<p><img src="bay1.gif" alt="bay1.gif" width="32" height="32"></p>

MESSAGE_END

Net::SMTP.start('smtp.myemail.com') do |smtp|
  smtp.send_message message, 'test@test.com',
                             'test1@test1.com
end

email is going. but image is not attaching ..

Can any one please help me .

--
Posted via http://www.ruby-forum.com/.

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...

···

Am 06.10.2012 00:10, schrieb Ferdous ara:

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 <test@test.com>
To: testuser <test@test.com>
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

<p><img src="bay1.gif" alt="bay1.gif" width="32" height="32"></p>

MESSAGE_END

Net::SMTP.start('smtp.myemail.com') do |smtp|
   smtp.send_message message, 'test@test.com',
                              'test1@test1.com
end

email is going. but image is not attaching ..

Can any one please help me .

--
<https://github.com/stomar/&gt;

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

···

--
Posted via http://www.ruby-forum.com/.

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 = "<img src='#{src}'>"

message = <<MESSAGE_END

···

From:test user <test@test.com>
To: testuser <test@test.com>
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

<p><img src="#{src}" alt="bay1.gif" width="32" height="32"></p>

MESSAGE_END

Net::SMTP.start('smtp.myemail.com') do |smtp|
  smtp.send_message message, 'test@test.com',
                             'test1@test1.com
end

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

--
Posted via http://www.ruby-forum.com/.

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 <test@test.com>
To: testuser <test@test.com>
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

<p><img src="#{src}" alt="test.png" width="32" height="32"></p>

MESSAGE_END

Net::SMTP.start('smtp.myemail.com') do |smtp|
  smtp.send_message message, 'test@test.com',
                             'test1@test1.com
end

still now luck

Please help me with this

--
Posted via http://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/.

HI yes
i can see in html format

http://fosiul.com/test.html

cat test.html

···

From: Fosiul alam <test@test.com>
To: Fosiul Alam <test@gmail.com>
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

<img
src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAAAAABVicqIAAAACXBIWXMAAAsT
AAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/
AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAABc0lEQVR42uyY4U3DMBCFPxAL
eIWs4BWOEbxCVggjuCPQEcoI8QjxCHSEeITHjxRBgSJaghDi7l+iyJ/uvXsn
K1fi5+sah5xRV+6Jy/W35XKIQzzxDvmLkJs3z7WFePrrVonhAoqOyzCdrhFG
nV+/IFerjVZiAB5qtS4tr7cNLEKtUD+T80tyjQCM0mwA9JL0uJyaJQM+lfNE
HUMmCwSbpARDHiBLMuiHDh41RIjDdyHPxo+wk5TpJMFOmgN5ZeMLXQIS+wqw
b4RxTKvl5JAW2u1hFCA93N2ZmX1jvD6U6+XALM09ADZdLNfNCXZaTqaDcJ9L
LbVsdut20hNfTVwvSRlWNj5RN0DdbCqtbMtzU6t1EmySDOLQB+IsdZCycRjh
NXKyO0q8zZKmZe8OkhQvSvy7i0Sp9AGoZdlXQCt7SB1A29Kdnxe/rTjEIf6z
wOVyTxzixjvEd5cb7xDfwt6JQxziOfFOfLrcE/fEp8s9+QdyPQ0AKbnfw2X3
XB8AAAAASUVORK5CYII=
'>

--
Posted via http://www.ruby-forum.com/.

no
i was checking in gmail .

but i dont see the 64 bit code ..

···

--
Posted via http://www.ruby-forum.com/.

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)

···

Am 06.10.2012 00:45, schrieb Ferdous ara:

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

--
<https://github.com/stomar/&gt;

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

···

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.

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 Rex

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

···

Am 06.10.2012 15:09, schrieb Ferdous ara:

HI yes
i can see in html format

--
<https://github.com/stomar/&gt;

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 ..

···

--
Posted via http://www.ruby-forum.com/\.

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?

···

Am 06.10.2012 12:28, schrieb Ferdous ara:

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 ..

--
<https://github.com/stomar/&gt;

unknown wrote in post #1078810:

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 ??

···

Am 06.10.2012 12:28, schrieb Ferdous ara:

--
Posted via http://www.ruby-forum.com/\.

unknown wrote in post #1078810:

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
   <p><img src="#{src}" alt="test.png" width="32" height="32"></p>
   MESSAGE_END

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

···

Am 06.10.2012 12:45, schrieb Ferdous ara:

Am 06.10.2012 12:28, schrieb Ferdous ara:

--
<https://github.com/stomar/&gt;