Flutter通过Mailer发送图像 [英] Flutter Sending Image via Mailer
本文介绍了Flutter通过Mailer发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我的代码找到解决方案。我正在尝试发送带有图片附件的邮件,但不知道该怎么做。我在该网站上搜索了几乎所有主题,但没有一个对我有帮助。
I'm trying to find a solution for my code. I'm trying to send mail with image attachment but I couldn't figured out how to do. I searched nearly all topics in this website but none of it helped me.
不使用附件,我能够发送电子邮件,但是当我使用附件并尝试发送图像时,什么也没有发生。我从代码中隐藏了私人信息。
Without using attachment, I'm able to send email but when I use attachment and trying to send my image, nothing happens. I hid private information from the code.
File newImage;
uploadImage() async {
final _storage = FirebaseStorage.instance;
final _picker = ImagePicker();
PickedFile image;
image = await _picker.getImage(source: ImageSource.camera);
var file = File(image.path);
String filName = basename(file.path);
// Upload to Firebase
var snapshot = await _storage.ref().child(filName).putFile(file).onComplete;
var downloadURL = await snapshot.ref.getDownloadURL();
setState(() {
imageUrl = downloadURL;
newImage = image; // PickedFile can't be assigned to variable type File
});
}
main(message) async{
var options = new SmtpOptions()
// Hidden
var transport = new SmtpTransport(options);
var envelope = new Envelope()
..from = 'example@mail.com'
..fromName = 'example'
..recipients = ['example2@mail.com']
..subject = 'example'
..attachments.add(new Attachment(file: new File(newImage))) // File can't be assigned to parameter type 'String'
..text = "$message";
transport.send(envelope)
.then((_) => print('email sent!'))
.catchError((e) => print('Error: $e'));
}
推荐答案
您可以改用以下代码:
..attachments.add(new Attachment(file: new File(newImage.path)))
这篇关于Flutter通过Mailer发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文