Question Html email with image and hyperlink (1 Viewer)

mari_hitz

Registered User.
Local time
Yesterday, 23:16
Joined
Nov 12, 2010
Messages
120
Hi all,

Hope you are good. Please note that I would like to know if you can guide me with my below inquiry.
I have a database that sends emails to a group of people. Is on Html. I would like to know if it is possible to add a picture to this email and also when the people click on the image go to an hyperlink.
I had searched on the web but I could not find anything. Can you guide me on how to do it?

Thanks in advance!
 

June7

AWF VIP
Local time
Yesterday, 22:16
Joined
Mar 9, 2014
Messages
5,466
What do you mean by "on" HTML?

Use Outlook automation to manipulate email object with an HTMLBody using HTML code tags. Tutorial site for HTML
https://www.w3schools.com/tags/tag_a.asp

Example VBA:
Code:
.HTMLBody = "<a href='https://www.w3schools.com'>" & _
"<img border='0' alt='W3Schools' src='logo_w3s.gif' width='100' height='100'></a>"

Outlook automation is common topic and many examples.

Post code you are having specific issue with.
 
Last edited:

mari_hitz

Registered User.
Local time
Yesterday, 23:16
Joined
Nov 12, 2010
Messages
120
Hi June7,

Please find below the code that I have. It currently sends the image, but it does not return the hyperlink. I would like that when you click on the image redirects you to a link. Is it possible this on access? Thanks!

Code:
 Private Sub Command23_Click()
Dim oApp As Outlook.Application
    Dim oEmail As MailItem
    Dim colAttach As Outlook.Attachments
    Dim oAttach As Outlook.Attachment

    'create new Outlook MailItem
    Set oApp = CreateObject("Outlook.Application")
    Set oEmail = oApp.CreateItem(olMailItem)
    'add graphic as attachment to Outlook message
    'change path to graphic as needed
    Set colAttach = oEmail.Attachments
    Set oAttach = colAttach.Add("C:\Users\msilv1\Desktop\emailtemplate.jpg")


    oEmail.Close olSave
    'change the src property to 'cid:your picture filename'
    'it will be changed to the correct cid when its sent.
    oEmail.HTMLBody = " < a href='http://www.nothing.com'><IMG src=""cid:emailtemplate.jpg"">< /a>"

    oEmail.Save
    oEmail.To = "marina.silva@nothing.com"
    oEmail.Subject = "test"
    oEmail.Send

    Set oEmail = Nothing
    Set colAttach = Nothing
    Set oAttach = Nothing
    Set oApp = Nothing
 

June7

AWF VIP
Local time
Yesterday, 22:16
Joined
Mar 9, 2014
Messages
5,466
On the email, hover cursor over image. Do you see message 'ctrl+click to follow link'? Link works for me.
 

mari_hitz

Registered User.
Local time
Yesterday, 23:16
Joined
Nov 12, 2010
Messages
120
On the email, hover cursor over image. Do you see message 'ctrl+click to follow link'? Link works for me.

Hi June7,

No, it doesn't appear anything :banghead:

On my email what appears is: the text "< a href='http://www.nothing.com" then the image and then text again "< /a>". When I hoover the mouse nothing appears,like the link has not been added.

Do you know why that can happen?

Thanks!
 

June7

AWF VIP
Local time
Yesterday, 22:16
Joined
Mar 9, 2014
Messages
5,466
You have space before a in < a href> and before / in < /a>. I did a test and those spaces cause issue. Remove them.

If still an issue try using HTML and BODY tags:
Code:
oEmail.HTMLBody = "<html><body><a href='http://www.nothing.com'><IMG src=""cid:emailtemplate.jpg""></a></body></html>"
However, I don't use that CID syntax, no idea what it is. I use full path to image and without any quotes or apostrophes around the image path.
 
Last edited:

mari_hitz

Registered User.
Local time
Yesterday, 23:16
Joined
Nov 12, 2010
Messages
120
You guys rock!

Thank you very much, this is solved and it worked with the suggestion made by June7.

Have a good day!
 

Users who are viewing this thread

Top Bottom