【发布时间】:2021-02-10 21:50:39
【问题描述】:
我在一个 android 应用程序中使用 mailer2 包进行颤振,我用它发送电子邮件。在这些电子邮件中,我有一个模板,我想在其中上传图像文件,但我不知道如何。
我要上传的图片在 Android 设备的内部存储中,所以我尝试使用此路径将图片加载到 HTML 中,但它没有加载。
<img src="/storage/emulated/0/DCIM/Camera/20210205_155258.jpg" alt="MyImages">
我需要知道如何在 Android 中将图像的内部路径加载到 <img src=" ruta-IMG">,以便我的 HTML 模板可以工作。
我在 Dart Flutter 中发送电子邮件的功能如下
sendMail() async {
String mensaje='';
var options = new GmailSmtpOptions()
..username = 'xxxxxxxxxxxxxxx@gmail.com'
..password = 'xxxxxxxxxxxxxxxxxxxxxx';
var emailTransport = new SmtpTransport(options);
var envelope = new Envelope()
..from = 'xxxxxxxxx@gmail.com'
..recipients.add('xxxxxxxxxxxxx@gmail.com')
..bccRecipients.add('xxxxxxxxxxxxxx@gmail.com')
..subject = ' images'
..text = 'This is a email message.'
..html = ''' [ HTML IMAGES] ''';
await
emailTransport
.send(envelope)
.then((envelope) => mensaje = 'Email sent!')
.catchError((e) => mensaje = 'Error occurred: $e');
return mensaje;
}
显示 [HTML IMAGES] 的 html 变量转到以下 HTML 模板,这是我遇到的错误。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Images</title>
<!--[if (mso 16)]>
<style type="text/css">
a {text-decoration: none;}
</style>
<![endif]-->
<!--[if gte mso 9]><style>sup { font-size: 100% !important; }</style><![endif]-->
<style type="text/css">
@media only screen and (max-width:600px) {
p,
ul li,
ol li,
a {
font-size: 16px!important
}
h1 {
font-size: 30px!important;
text-align: center
}
h2 {
font-size: 26px!important;
text-align: center
}
h3 {
font-size: 20px!important;
text-align: center
}
h1 a {
font-size: 30px!important
}
h2 a {
font-size: 26px!important
}
h3 a {
font-size: 20px!important
}
.es-menu td a {
font-size: 16px!important
}
.es-header-body p,
.es-header-body ul li,
.es-header-body ol li,
.es-header-body a {
font-size: 16px!important
}
.es-footer-body p,
.es-footer-body ul li,
.es-footer-body ol li,
.es-footer-body a {
font-size: 16px!important
}
.es-infoblock p,
.es-infoblock ul li,
.es-infoblock ol li,
.es-infoblock a {
font-size: 12px!important
}
*[class="gmail-fix"] {
display: none!important
}
.es-m-txt-c,
.es-m-txt-c h1,
.es-m-txt-c h2,
.es-m-txt-c h3 {
text-align: center!important
}
.es-m-txt-r,
.es-m-txt-r h1,
.es-m-txt-r h2,
.es-m-txt-r h3 {
text-align: right!important
}
.es-m-txt-l,
.es-m-txt-l h1,
.es-m-txt-l h2,
.es-m-txt-l h3 {
text-align: left!important
}
.es-m-txt-r img,
.es-m-txt-c img,
.es-m-txt-l img {
display: inline!important
}
.es-button-border {
display: block!important
}
.es-button {
font-size: 20px!important;
display: block!important;
border-width: 10px 0px 10px 0px!important
}
.es-btn-fw {
border-width: 10px 0px!important;
text-align: center!important
}
.es-adaptive table,
.es-btn-fw,
.es-btn-fw-brdr,
.es-left,
.es-right {
width: 100%!important
}
.es-content table,
.es-header table,
.es-footer table,
.es-content,
.es-footer,
.es-header {
width: 100%!important;
max-width: 600px!important
}
.es-adapt-td {
display: block!important;
width: 100%!important
}
.adapt-img {
width: 100%!important;
height: auto!important
}
.es-m-p0 {
padding: 0px!important
}
.es-m-p0r {
padding-right: 0px!important
}
.es-m-p0l {
padding-left: 0px!important
}
.es-m-p0t {
padding-top: 0px!important
}
.es-m-p0b {
padding-bottom: 0!important
}
.es-m-p20b {
padding-bottom: 20px!important
}
.es-mobile-hidden,
.es-hidden {
display: none!important
}
.es-desk-hidden {
display: table-row!important;
width: auto!important;
overflow: visible!important;
float: none!important;
max-height: inherit!important;
line-height: inherit!important
}
.es-desk-menu-hidden {
display: table-cell!important
}
table.es-table-not-adapt,
.esd-block-html table {
width: auto!important
}
table.es-social {
display: inline-block!important
}
table.es-social td {
display: inline-block!important
}
}
#outlook a {
padding: 0;
}
.ExternalClass {
width: 100%;
}
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
.es-button {
mso-style-priority: 100!important;
text-decoration: none!important;
}
a[x-apple-data-detectors] {
color: inherit!important;
text-decoration: none!important;
font-size: inherit!important;
font-family: inherit!important;
font-weight: inherit!important;
line-height: inherit!important;
}
.es-desk-hidden {
display: none;
float: left;
overflow: hidden;
width: 0;
max-height: 0;
line-height: 0;
mso-hide: all;
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" class="es-right" align="right" style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;float:right;">
<tr style="border-collapse:collapse;">
<td width="270" align="left" style="padding:0;Margin:0;">
<table cellpadding="0" cellspacing="0" width="100%" style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;">
<tr style="border-collapse:collapse;">
</tr>
<tr style="border-collapse:collapse;">
<td align="center" style="padding:0;Margin:0;padding-top:10px;">
<h3 style="Margin:0;line-height:120%;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;font-size:20px;font-style:normal;font-weight:normal;color:#333333;">Image Title Goes Here</h3>
<!--PROBLEM WITH IMAGE PATH--><img src="/storage/emulated/0/DCIM/Camera/20210205_155258.jpg" alt="MyImages"><!--PROBLEM WITH IMAGE PATH-->
</td>
</tr>
<tr style="border-collapse:collapse;">
<td align="left" style="padding:0;Margin:0;padding-top:5px;">
<p style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-size:14px;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:150%;color:#333333;">You can change the size, layout or link of the downloaded image in the left-hand side menu.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
问题出现在 HTML 模板中,这是我需要从内部 Android 存储调用的文件的路径...标记为 <! - PROBLEM WITH THE IMAGE PATH ->
这对我有用,但我需要将 URL 更改为本地路径,但我不知道该怎么做。我展示了与 url 一起使用的图像。 Img with URL
将 URL 更改为 Local 的路径是
-> /storage/emulated/0/DCIM/Camera/20210205_155258.jpg,这条路我需要..
【问题讨论】:
-
您使用哪个应用程序来显示 html?您要发送 html 电子邮件吗?
-
@blackapps- 我更改了帖子以更好地理解
元素路径的错误
-
@Nautilus 您是否尝试过读取图像并将其转换为 base64 字符串?它看起来像这样
<img src="data:image/png;base64,......." > -
@Nautilus 您可以将其附加到您的 HTML 字符串中。样品
<image src="$encodedImage">。请尝试使用 bezkoder.com/dart-base64-image 将您的图像编码为 base64。 -
我投票结束这个问题,因为标题不是英文的