Last active
April 14, 2020 13:37
-
-
Save paulo9mv/2d72bbc11cce2e9249e7030e4e3f2e55 to your computer and use it in GitHub Desktop.
Adiciona o método sendMessage()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:mailer/mailer.dart'; | |
import 'package:mailer/smtp_server.dart'; | |
class Email { | |
String _username; | |
var smtpServer; | |
Email(String username, String password){ | |
_username = username; | |
smtpServer = gmail(_username, password); | |
} | |
//Envia um email para o destinatário, contendo a mensagem com o nome do sorteado | |
Future<bool> sendMessage(String mensagem, String destinatario, String assunto) async { | |
//Configurar a mensagem | |
final message = Message() | |
..from = Address(_username, 'Nome') | |
..recipients.add(destinatario) | |
..subject = assunto | |
..text = mensagem; | |
try { | |
final sendReport = await send(message, smtpServer); | |
print('Message sent: ' + sendReport.toString()); | |
return true; | |
} on MailerException catch (e) { | |
print('Message not sent.'); | |
for (var p in e.problems) { | |
print('Problem: ${p.code}: ${p.msg}'); | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment