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 .
on 2012-10-06 00:09
on 2012-10-06 00:41
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...
on 2012-10-06 00:45
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
on 2012-10-06 01:07
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 2012-10-06 02:34
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
on 2012-10-06 11:37
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
on 2012-10-06 12:04
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
on 2012-10-06 12:20
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
on 2012-10-06 12:28
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 ..
on 2012-10-06 12:39
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?
on 2012-10-06 12:45
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 ??
on 2012-10-06 14:14
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
on 2012-10-06 14:53
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 <p><img src="#{src}" alt="test.png" width="32" height="32"></p> MESSAGE_END File.open('test.html', 'w') {|f| f.puts message }
on 2012-10-06 15:09
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= '>
on 2012-10-06 16:27
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?
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.