Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
sona_sa
Creator II
Creator II

Insert an Image in Mail Body.

Hi Friends,

I want to send clipboard image by Outlook Box with any attachment. It should to go as an image in mail body. For this I am using the below macro. Please check it.

But my image is not going properly in mail body. I am able to send by attachment but not in mailbody.

sub mSendMail

          Dim objOutlk 'Outlook

          Dim objMail 'Email item

          Dim strMsg

          dim strMailTo

          dim sString

          dim oldFormat

          Dim Rng

          Const olMailItem = 0

          Const CdoReferenceTypeName = 1

          Set objOutlk = CreateObject("Outlook.Application")

          Set objMail = objOutlk.createitem(olMailItem)

          Set Rng = Nothing

          objMail.To = "amit.kumar@teamcomputers.com"

          objMail.subject = "OMS DASHBOARD"

          ActiveDocument.ActiveSheet.CopyBitmapToClipboard true

          ActiveDocument.Sheets("Dashboard-email").ExportBitmapToFile "\\172.16.11.211\Documents\OMS DASHBOARD.jpeg"

          objMail.attachments.add("\\172.16.11.211\Documents\OMS DASHBOARD.jpeg")

          strMsg = "This is an automatic generated email from QlikView for OMS DASHBOARD."

          objMail.body = strMsg

    objMail.HTMLBODY = "<HTML><BODY><img align=baseline border=0 hspace=0 src='cid:\\172.16.11.211\Documents\test.jpeg'</BODY></HTML>"

            objMail.Send

          Set objMail = Nothing

          Set objOutlk = Nothing

    Msgbox " Mail delivered"

end sub

7 Replies
Not applicable

To do that, use this simple trick.

Right click on the object, click "Print..." then a popup message(Print Object) will appear (it may different, but in standard settings normally this will appear).

After you click "Print.." a new tab/window will appear, now you have your object in this new tab/window then right click to show the menu, you can copy as an image or directly send as an email, depend on what browser you were using.

If there's no new tab/windows appear then you must allow for the new tab/windows to appear in the browser setting or click "press here" in the "print object" popup message.

So now you can paste it as an image to the body of email or any app. like power point or excel and else..

I will not recommend to use a macro because its unstable(depends on the browser), may reduce qv performance, and hard to maintain, etc.

Use macro only if there's no other solutions

hope it help..

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi

     Check these 2 lines in your code

          objMail.attachments.add("\\172.16.11.211\Documents\OMS DASHBOARD.jpeg")

               and

          objMail.HTMLBODY = "<HTML><BODY><img align=baseline border=0 hspace=0 src='cid:\\172.16.11.211\Documents\test.jpeg'</BODY></HTML>"

filename is diff may that doesn't exist in that location and img tag not properly closed

Celambarasan

sona_sa
Creator II
Creator II
Author

Sorry I posted worng code:

sub mSendMail

          Dim objOutlk 'Outlook

          Dim objMail 'Email item

          Dim strMsg

          dim strMailTo

          dim sString

          dim oldFormat

          Dim Rng

          Const olMailItem = 0

          Const CdoReferenceTypeName = 1

          Set objOutlk = CreateObject("Outlook.Application")

          Set objMail = objOutlk.createitem(olMailItem)

          Set Rng = Nothing

          objMail.To = "amit.kumar@teamcomputers.com"

          objMail.subject = "OMS DASHBOARD"

          ActiveDocument.ActiveSheet.CopyBitmapToClipboard true

          ActiveDocument.Sheets("Dashboard-email").ExportBitmapToFile "\\172.16.11.211\Documents\OMS DASHBOARD.jpeg"

          objMail.attachments.add("\\172.16.11.211\Documents\OMS DASHBOARD.jpeg")

          strMsg = "This is an automatic generated email from QlikView for OMS DASHBOARD."

          objMail.body = strMsg

    objMail.HTMLBODY = "<HTML><BODY><img align=baseline border=0 hspace=0 src='cid:\\172.16.11.211\Documents\OMS DASHBOARD.jpeg'</BODY></HTML>"

            objMail.Send

          Set objMail = Nothing

          Set objOutlk = Nothing

    Msgbox " Mail delivered"

end sub

Anonymous
Not applicable

Akumar,

Did you solve this problem? If yes, please shere the solution.

Thanks in advance.

Not applicable

Hi Guys

Ive got a solution for this... After a long long stuggle - Please see below.

function SendMail()

 

          Dim objEmail   

 

          Const cdoSendUsingPort = 2

          Const cdoAnonymous = 0

          Const cdoBasic = 1

          Const cdoNTLM = 2

 

          Set SMTP = ActiveDocument.GetVariable("SMTPServer")

    

    Set SMTPData = SMTP.GetContent

   

    ActiveDocument.GetApplication.WaitForIdle

          SMTPServer = SMTPData.String

          userName = "xxx@xxx.co.za"

          userPassword = "password"

          Const SMTPPort = 25                             ' Port number for SMTP

          Const SMTPTimeout = 60                ' Timeout for SMTP in seconds

 

 

          'Sending mail

          Set objEmail = CreateObject("CDO.Message")

          Set objConf = objEmail.Configuration

          Set objFlds = objConf.Fields

          With objFlds

                    '---------------------------------------------------------------------

                       ' SMTP server details

                       .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

                       .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

                       .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

                      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout

                       .Update

                    '---------------------------------------------------------------------

          End With

 

          Set EmailTo = ActiveDocument.GetVariable("EmailTo")

    Set EmailToData = EmailTo.GetContent

          objEmail.To = EmailToData.String

          ActiveDocument.GetApplication.WaitForIdle

 

 

          Set EmailFrom = ActiveDocument.GetVariable("EmailFrom")

    Set EmailFromData = EmailFrom.GetContent                              'Email Recipient

          objEmail.From = EmailFromData.String

 

          Set EmailSubject = ActiveDocument.GetVariable("EmailSubject")

    Set EmailSubjectData = EmailSubject.GetContent                                                  'Email Sender

          objEmail.Subject = EmailSubjectData.String

 

          Set EmailBody = ActiveDocument.GetVariable("EmailBody")

    Set EmailBodyData = EmailBody.GetContent                                                  ' Subject

          objEmail.TextBody = EmailBodyData.String

 

          objEmail.HTMLBODY = "<HTML><BODY><img align=baseline border=0 hspace=0 src='C:\Test.jpg'</BODY></HTML>"

   

 

          objEmail.Send

 

          Set objFlds = Nothing

          Set objConf = Nothing

          Set objEmail = Nothing

msgbox ("Mail Sent")

 

end function

Anonymous
Not applicable

I am trying the same but the image is sent in email body only if I am sending it to myself,

otherwise it goes as attachment only and only cross sign is shown in email body instead of image.

Please tell me what can be the issue???????

Regards

Nitin

Anonymous
Not applicable

Hello,

According to me, you have a problem with the command syntax.

For me works it:

<IMG src=""CH16.png""> </IMG>"

  objMsg.AddAttachment   ImagesAtt(0)

ImagesAtt(0) - variable with file and location


Regards

Jacek