我正在建立一个通知系统,该系统将发送带有包含图像的html表的电子邮件。
图像在实际页面中显示良好。我正在用硒捕获表源(将所有相对路径更改为完整路径)
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')
现在我正在使用mailgun api发送电子邮件
r = requests.post(
"https://api.mailgun.net/version/my domain name/messages",
auth=("api", "my api key"),
data={"from": "mailgun@mydomain",
"to": ["[email protected]", "[email protected]"],
"subject": "random subject",
"html": resp})
发送电子邮件没有问题,但是图像没有发送电子邮件的方式,它们的链接也发生了变化示例实际页面
基本上图像从此改变:
<img src="https://p3.aleado.com/pic/?system=auto&date=2019-11-07&auct=243&bid=70048&number=1&w=72" load_src="https://p3.aleado.com/pic/?system=auto&date=2019-11-07&auct=243&bid=70048&number=1&w=72" border="0" name="img_preview" width="72">
为此:
<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&date=2019-11-07&auct=243&bid=70048&number=1&w=72" name="m_-9099380790990105554_img_preview" class="CToWUd" width="72" border="0">
我尝试过Base64,但Gmail不支持它,并在其位置显示空白
我在这里做错什么,如何嵌入这些链接?
任何建议都会有所帮助。
提前感谢
不要以为你做错了什么。默认情况下,Gmail下载所有图像并将其放置在代理服务器上。提供图片后,它的速度比Gmail服务器上已经快。根据Litmus的说法,该代理于2013年首次启动。
[缓存图像时,它是从原始服务器下载的,存储在代理服务器上。缓存图像的后续视图将始终从代理服务器而不是原始服务器显示,有效地重新路由所有图片下载以及图片下载随附的相关跟踪数据。
您可以阅读石蕊here的全文。