-3
When I try to send a message without an image, the Mailer shows an error, but if I take the field ..attachments.add(new Fileattachment(_imagemAn,)); the message is sent normally without presenting the error, however, the funny thing is that I am not getting it, if in that same message that was giving error by being sent without image, containing ..attachments.add(new Fileattachment(_imagemAn,));, just add an image and the message is sent.
it’s almost as if I was forced to send with image, I need to say that ..attachments.add(new Fileattachment(_imagemAn,)); equal to or different from nil?
I’m sweating the Mailer API: 4.0.0.
More directly, when the message is sent only if all fields are filled in, if one of the fields is not filled in, how to correct?
This is the code I’m using, this is the screen where the message is displayed before sending, as a confirmation page before sending.
class PaginadeBoasVindasAN extends StatelessWidget {
String _localAn;
String _problemaAn;
File _imagemAn;
File _imagemGaleriaAn;
PaginadeBoasVindasAN(
this._localAn,
this._problemaAn,
this._imagemAn,
this._imagemGaleriaAn,
);
// Aqui vamos criar o e-mail - smtp
enviarMensagem() async {
String username = '@gmail.com';
String password = '@#';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address('Sem identificação', ' ')
..recipients.add('@gmail.com')
..ccRecipients.addAll(['[email protected]', '[email protected]'])
..bccRecipients.add(Address('[email protected]'))
..subject = '$_localAn :: ${DateTime.now()}'
..text = 'LOCAL: $_localAn,n\: $_problemaAn'
..attachments.add(FileAttachment(_imagemAn,))
..attachments.add(FileAttachment(_imagemGaleriaAn,));
try {
final sendReport = await send(message, smtpServer);
print('Mensagem enviada: ' + sendReport.toString());
} on MailerException catch (e) {
print('Mensagem não enviada.');
for (var p in e.problems) {
print('Problema: ${p.code}: ${p.msg}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
Your question is a little confusing, but come on... If you want the image to be optional for sending, you need to make a condition to send or not the same, for example
if (_imageAn != null) message.FileAttachment(_imagemAn,)
. Otherwise do not even call this function, because theFileAttachment
will try to create something that does not exist.– Matheus Ribeiro
I’m sorry for the confusion in the message, but you presented me something that I believe will work, I’m new and studying on my own, with I would implement this condition to my code?
– Lucas Gomes