1

I am making a notification system which sends emails with a html table which has images.

the images shows up fine in the actual page. I am grabbing the table source with selenium (changing all relative paths to full paths)

    for attr in driver.find_elements_by_xpath('//table[@id="mainTable"]/tbody/tr[contains(@id, "cell_")]'):

        #gettin the image link

        imgattr = attr.find_element_by_xpath('.//td[4]/a[1]/img[1]')
        imglink = imgattr.get_attribute('src')

        #changing to full path and setting that with javascript

        driver.execute_script('arguments[0].setAttribute("src","{}");'.format(urljoin(root_url, imglink)), imgattr)
        driver.execute_script('arguments[0].setAttribute("width","{}");'.format('72'), imgattr)
        driver.execute_script('arguments[0].setAttribute("height","{}");'.format('54'), imgattr)

        #getting the element (table) again 
        #with image links changed to full path

        elem = driver.find_element_by_xpath('//table[@id="mainTable"]')
        resp = elem.get_attribute('innerHTML')

now i am using mailgun api to send a email

    r = requests.post(
    "https://api.mailgun.net/version/my domain name/messages",
    auth=("api", "my api key"),
    data={"from": "mailgun@mydomain",
    "to": ["recipient1@gmail.com", "recipient2@gmail.com"],
    "subject": "random subject",
    "html": resp})

email gets sent no issues but the images dont how, their links change when sent in email example Actual Page enter image description here

Sent email inspect element, links change from source to a blank one enter image description here

Basically the image changes from this:

<img src="https://p3.aleado.com/pic/?system=auto&amp;date=2019-11-07&amp;auct=243&amp;bid=70048&amp;number=1&amp;w=72" load_src="https://p3.aleado.com/pic/?system=auto&amp;date=2019-11-07&amp;auct=243&amp;bid=70048&amp;number=1&amp;w=72" border="0" name="img_preview" width="72">

To this:

<img src="https://ci6.googleusercontent.com/proxy/qQR9p1-B2oWM3V-bVJssDVajsvZN9irPqHctNMUr6jTsgKmuZFP30fcTB54a-wtpM_H6rL0K_Fz7huR4oMPVTISpvE7XSJkwwFbFMZc6B2yVviL28WMGzAXGzlso8RHgGTjxGwqGS7_XAQ=s0-d-e1-ft#https://p3.aleado.com/pic/?system=auto&amp;date=2019-11-07&amp;auct=243&amp;bid=70048&amp;number=1&amp;w=72" name="m_-9099380790990105554_img_preview" class="CToWUd" width="72" border="0">

I have tried Base64 but Gmail doesn't support it and show blanks in its place

What am i doing wrong here and how can i embed those links?

any suggestions would be helpful.

Thanks in advance

Syfer
  • 4,262
  • 3
  • 20
  • 37
Shantanu Bedajna
  • 559
  • 10
  • 34

1 Answers1

1

Don't think you are doing anything wrong. By default Gmail downloads all the images and places it on a proxy server. When the images are served, its faster as its already on Gmail servers.According to Litmus the proxy first started in 2013.

When an image is cached, it is downloaded from the original server and stored on a proxy server. Subsequent views of the cached image will always display from the proxy server rather than the original server, effectively re-routing all the image downloads along with the associated tracking data that comes with the image download.

You can read the full article from Litmus here.

Syfer
  • 4,262
  • 3
  • 20
  • 37
  • ahh i see, any suggestions on how can i embed images and why they are not working ? – Shantanu Bedajna Nov 06 '19 at 14:11
  • 1
    @ShantanuShady Embedding images in emails can be found [here](https://stackoverflow.com/questions/6706891/embedding-image-in-html-email). Just a quick note. Those embedded images might show up as attachments in Gmail if they are accepted and shown. – Syfer Nov 06 '19 at 20:10