Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

dart - mailer dependency for flutter not working

I am trying to send an email using the mailer plugin for flutter but i keep on getting these errors

I/flutter (27541): Message not sent. 
I/flutter (27541): After sending HELO localhost, response did not start with any of: [2].
I/flutter (27541): Response from server: < 421 Local Error, closing transmission channel

This is the response I get after printing print(e.runtimeType.toString()); = I/flutter (27541): SmtpClientCommunicationException

This is my code below ,which I implemented using the official documentation:

import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  String username = "[email protected]";
  String password = "Password";

  sendMail() async {
   final smtpServer = gmail("$username", "$password");
   
    // Create our email message.
    final message = Message()
      ..from = Address("[email protected]", 'My Name')
      ..recipients.add('[email protected]')
      ..subject = 'Test Dart Mailer library ::'
      ..text = 'This is the plain text.
This is line 2 of the text part.' //body of the email
      ..html = '<h1>Test</h1><p>Hey!</p>';
    try {
      final sendReport = await send(message, smtpServer);
      print('Message sent: ' + sendReport.toString()); //print if the email is sent
    } on MailerException catch (e) {
      print(e.runtimeType.toString());
      print('Message not sent. 
' + e.toString()); //print if the email is not sent
      // e.toString() will show why the email is not sending
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: 500,
        width: double.infinity,
        child: Center(
          child: RaisedButton(
            child: Text("Press"),
            onPressed: () {
              sendMail();
            },
          ),
        ),
      ),
    );
  }
}

question from:https://stackoverflow.com/questions/65838084/mailer-dependency-for-flutter-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...