Send Email with Picture in the Message Body (Solved)

Send Email with Picture in the Message Body (Solved)

Postby anserkk » Fri Apr 17, 2009 4:04 pm

Hi,

How to Send an Email with Picture in the Message Body ? I beleive it is something to do with MIME Encoding
Do anybody know how to convert an HTML mail to Mime ?.

My requirement:

I want to send an html mail with an inline picture in it ie. Picture along with the Body of the email message and not as an attachment. I understand that the inline jpg picture should be converted to mime encoding with boundry.

I am developing an email sending app using the windows CDO technology. I have the email message composed in html format with an inline picture, but the html contains only the reference path of the picture in the email sender's pc. The recpients PC will not display the inline picture (Picture along with the Body of the email message). I need this jpg pic to be sent along with the email. Anybody know how to do this ?

Right now the composed email msg is saved as .htm file and the contents of this .htm file is read to a variable from FWH and then this variable is assigned to the MessageBody

For Eg: oEmailMsg:HTMLBody:=cHtmlContent

The Html email should have Content ID (cid) with a unique no and the jpg picture should be converted as per mime coding and bundled along with the html file.

Anybody here have experience in this subject or point me to the right direction?

Regards

Anser
Last edited by anserkk on Sat Apr 18, 2009 5:51 am, edited 1 time in total.
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Send Email with Picture in the Message Body

Postby anserkk » Sat Apr 18, 2009 5:50 am

Hi Friends,

Solved the issue. This can be done using AddRelatedBodyPart command

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Send Email with Picture in the Message Body (Solved)

Postby driessen » Sun Apr 19, 2009 12:08 am

Anser,

Is it possible to provide us with an example of an email with a picture in the message body ?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Send Email with Picture in the Message Body (Solved)

Postby anserkk » Mon Apr 20, 2009 5:45 am

Dear Mr.Michel,

Here is the sample code. :D

Code: Select all  Expand view
// Set up Email Configurations like SMTP, SMTP Port, UserID, Password Etc.
oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oEmailCfg:Fields
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := "smtp.gmail.com"
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := 465
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2   // Remote=2, local=1
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.
  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := .T.
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := cSendMailId  // ans@gmail.com
  :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cSendMailIdPass   // Pass
  :Update()
END WITH

// Create Email Message with To,Bcc,CC, Subject, Attachments, Email Message Content,
//  Inline Pictures if any etc. and then Send the Message
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
   :Configuration = oEmailCfg   // Mail Config. Object
   :From = chr(34)+" "+cFromName+" "+chr(34)+ "<"+cFromID+">" // Disp in the From Col
   :To = cToEmailId         // To email address
   :Subject = cSubject     // Subject of the Email Message
   :ReplyTo = cReplyId     // If specified, then Reply mail is send to this ID
   :Sender = oMailer:cAcknowId  // Read Receipt message is send to this
   :Organization = oMailer:cFromName    // "Anser's "
   If !empty(cAttachment)    // Attachements if any
      :AddAttachment(oMailer:cAttachment)    // For Eg "c:\LCd Projector.txt"
   Endif
   :MDNRequested = .T.     // Request Read Receipt
    IF !empty(cInlineAttachment) // Inline Pic Attachement to the Body of the msg
      :AddRelatedBodyPart("E:\Apps\Mailer\Files\Error.Jpg","Error.jpg",0)
    Endif
    :HTMLBody = cHtml  // cHtml contains the HTML Code contents and NOT the HTML File
    :Send()
END WITH


Mr. Micheal the above code is working fine here.

I am getting wierd results when I try to send it using a timer (repeated sending) For eg. sending 10 email messages in a minute, especially when the size of the email message is bigger than 200KB. I have 1000's of email address in an excel file and I want to send 12 or 20 or n number of email messages in a minute. Once the email messages are send; each record in the Excel file will be updated with the Send Date and Time.

I think the Timer action is activated even before the send activity of the previous timer action is finished. I will have to figure it out. :roll:

It works only when the Timer Action is called for the first time, the second time the app hangs.

I even used MsgRun to call the :Send(), so that the activities get paused till I finish the Send(), unfortunately not getting the expected result. I assume the next Timer Action get's fired even before the Send() is finished and FWH events are not getting fired as per the sequence expected by me
Code: Select all  Expand view
MsgRun("Sending Email from row "+str(nRow,6),"Please wait", { || oEmailMsg:Send() } )


Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests