如何将图片(jpg / png / etc)嵌入html并通过邮件发送出去 [英] How to embed a picture (jpg/png/etc,) into html and email it out with mail
问题描述
背景:我正在尝试基于html的电子邮件,因为它用途更多(我是html的新手)。我已经使用HTML玩了几个小时。到目前为止,我可以将表格,不同的标题和链接等嵌入到我发送的电子邮件中,但是在嵌入图片方面有很大的困难。
我认为这可能是客户特定的问题-但是Hotmail,Outlook和G-mail均不显示附件图像。我只看到带有alt( alternative )文本的框。
#!/ bin / bash
h_test = mytest.html
echo这是一封测试电子邮件> TESTEMAILTESTEMAILTESTEMAIL.txt
echo< html>
< head>
< title> HTML E-mail< / title>
< / head>
< body>
< p> b> b>注意:< / b>这只是测试电子邮件。< / p>
< p> ; / p>
< h2>表1< / h2>
< table style = width: 25%>
<
< td>纽约< / td>
< A&#39;< / td>
< / tr>
< tr>
< td>悉尼< td>
< Australia< / td>
< / tr>
< ; tr>
< td>伊斯坦布尔// td>
< td>土耳其// td>
< / tr>
< / table>
< h2>表2< / h2>
<表格border = 1; style = width:50%>
< tr>
<月< / th>
< th>储蓄// th
< / tr>
< ; tr>
< td>一月< / td>
< td> $ 100< / td>
< / tr>
< tr>
< td> 2月/ td;
< td> $ 80< / td>
< / tr>
< / table>
< h2>图片1< / h2>
< img src ='https://www.google.com.au/search?q = image + test& espv = 2& biw = 1366& bih = 663& source = lnms& tbm = isch& sa = X& ved = 0CAYQ_AUoAWoVChMI1_fn1MrNyAIVITamCh32cQej#imgrc = driDe9TNSAxoAM%3A'alt ='您应该在看图片'>
< h2>链接< / h2>
< a href =’http://www.google.com’>点击此处< / a>
< / body>
< / html>> $ h_test
echo>>正在发送电子邮件...
`mail -s $(echo -e这是Subject\nContent-Type:text / html) my_email@me.com< mytest.html `
echo ...已发送电子邮件
研究:我看过网站,例如此网站,但没有用。我也查找了类似的网站 stackexchange 上的问题,但无法使其正常工作。 / p>
问:如何将图片嵌入到电子邮件中?
您可以将图像自身嵌入html中,并以base64编码,如下所示:
< img src = data:image / png; base64,iVBORw0KGg .... />
例如查看此站点生成base64终结符: http://dataurl.net/#dataurlmaker
更新:
我现在了解到,这并不适用于所有电子邮件客户端:
一些示例:
- iOS Mail 是
- Outlook 2003 是
- Outlook 2007+ 否
- Apple Mail 是
- 雅虎!邮件否
- Gmail 否
- Android默认值是
通过此链接> https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/
Background: I am trying to my emails html based, as it is more versatile (I am new to html). I have been playing around with html for a few hours. I can so far embed tables, and different headings and links etc. into the emails that I send out, but have massive difficulty with embedding pictures.
I thought it might a client specific problem - but Hotmail, Outlook and G-mail all don't show the attached image. All I see is the the box with the alt (alternative) text.
#!/bin/bash
h_test=mytest.html
echo "This is a test email"> TESTEMAILTESTEMAILTESTEMAIL.txt
echo "<html>
<head>
<title>HTML E-mail</title>
</head>
<body>
<p><b>Note:</b> This is just a test email.</p>
<p>Trying to do different things all in one email.</p>
<h2>Table 1</h2>
<table style="width:25%">
<tr>
<td>New York</td>
<td>UNITED STATE OF AMERICA</td>
</tr>
<tr>
<td>Sydney</td>
<td>AUSTRALIA</td>
</tr>
<tr>
<td>Istanbul</td>
<td>TURKEY</td>
</tr>
</table>
<h2>Table 2</h2>
<table border="1"; style="width:50%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
<h2>Image 1</h2>
<img src='https://www.google.com.au/search?q=image+test&espv=2&biw=1366&bih=663&source=lnms&tbm=isch&sa=X&ved=0CAYQ_AUoAWoVChMI1_fn1MrNyAIVITamCh32cQej#imgrc=driDe9TNSAxoAM%3A' alt='You should be seeing a picture'>
<h2>Link</h2>
<a href='http://www.google.com'>Click Here</a>
</body>
</html>" > $h_test
echo ">> Sending email..."
`mail -s "$(echo -e "This is Subject\nContent-Type: text/html")" my_email@me.com < mytest.html`
echo "...e-mail sent"
Research: I have looked at websites such as this site, but didn't work. I have also looked up similiar questions on stackexchange but couldn't make it work.
Q: How can I embed pictures into my emails?
You can embed images in the html it self,base64-encoded, like this:
<img src="data:image/png;base64,iVBORw0KGg....." />
Look for example at this site to generate the base64 endoding: http://dataurl.net/#dataurlmaker
Update: I have now learned that this does not work in all email-clients: Some examples:
- iOS Mail Yes
- Outlook 2003 Yes
- Outlook 2007+ No
- Apple Mail Yes
- Yahoo! Mail No
- Gmail No
- Android default Yes
from this link https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/
这篇关于如何将图片(jpg / png / etc)嵌入html并通过邮件发送出去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!