使用Flutter_email_sender中的电子邮件中添加图像
我正在使用Flutter/Dart创建一个Android应用程序,我想在其中发送带有嵌入式图像的电子邮件。
因此,我安装了Flutter_email_sender并尝试使用它。它可以发送带有文本的电子邮件,但是当我尝试添加图像时。它没有出现在电子邮件应用程序中。
这是我的代码:
// DataUser.pathImage is the path of the image (/data/src/0/cache/hi.jpg)
// extension(DataUser.pathImage).substring(1) => "jpg"
// DataUser.emailText.split("\n").join("<br>") is the text of the user that will be send
// ex: "Hi\nYes\nNo" => "Hi<br>Yes<br>No"
final bytes = File(DataUser.pathImage).readAsBytesSync();
String image64 = base64.encode(bytes);
String result = "<p>" + DataUser.emailText.split("\n").join("<br>") + "<br>";
result += "<img src=\"data:image/${extension(DataUser.pathImage).substring(1)};base64," + image64;
result += "\" alt=\"image\" />";
result += "</p>";
final Email email = Email(
body: result,
subject: "Pointage",
recipients: DataUser.adresse,
attachmentPaths: DataUser.filePath,
isHTML: true,
);
await FlutterEmailSender.send(email);
有没有办法发送包含此扩展名的映像的电子邮件?
I am creating an Android application with flutter/dart and I want to send an email with an embedded image inside.
So I installed flutter_email_sender and tried to use it. It works to send an email with text, but when I tried to add an image. It doesn't appear in the email application.
Here is my code:
// DataUser.pathImage is the path of the image (/data/src/0/cache/hi.jpg)
// extension(DataUser.pathImage).substring(1) => "jpg"
// DataUser.emailText.split("\n").join("<br>") is the text of the user that will be send
// ex: "Hi\nYes\nNo" => "Hi<br>Yes<br>No"
final bytes = File(DataUser.pathImage).readAsBytesSync();
String image64 = base64.encode(bytes);
String result = "<p>" + DataUser.emailText.split("\n").join("<br>") + "<br>";
result += "<img src=\"data:image/${extension(DataUser.pathImage).substring(1)};base64," + image64;
result += "\" alt=\"image\" />";
result += "</p>";
final Email email = Email(
body: result,
subject: "Pointage",
recipients: DataUser.adresse,
attachmentPaths: DataUser.filePath,
isHTML: true,
);
await FlutterEmailSender.send(email);
Is there a way to send an email containing an image with this extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
在电子邮件对象中,附件接受文件路径列表,即列表。您可以检查完整的示例在这里。
创建一个附件的字符串列表:
现在将您的映像路径(字符串)添加到此列表中。
(我认为您通过添加.readasbyTessync()犯了一个错误,我认为这不是必要的)。
假设用户从画廊中选择图像:
现在将此附件列表传递给电子邮件对象。
In Email object, attachmentPaths accepts list of file paths i.e. List. You can check the complete example here.
Create a list of strings for attachments file paths:
Now add your image path (string) to this list.
(I think you are doing a mistake by adding .readAsBytesSync(), I don't think that's necessary).
Let's say user picks an image from gallery:
Now pass this attachments list to the Email object.