Net::Async::SMTP::Client - sending email with IO::Async
#!/usr/bin/env perl use strict; use warnings; use IO::Async::Loop; use Net::Async::SMTP::Client; use Email::Simple; my $email = Email::Simple->create( header => [ From => 'someone@example.com', To => 'other@example.com', Subject => 'NaSMTP test', ], attributes => { encoding => "8bitmime", charset => "UTF-8", }, body_str => '... text ...', ); my $loop = IO::Async::Loop->new; $loop->add( my $smtp = Net::Async::SMTP::Client->new( domain => 'example.com', ) ); $smtp->connected->then(sub { $smtp->login( user => '...', pass => '...', ) })->then(sub { $smtp->send( to => 'someone@example.com', from => 'other@example.com', data => $email->as_string, ) })->get;
Provides basic email sending capability for IO::Async, using the Protocol::SMTP implementation.
See "DESCRIPTION" in Protocol::SMTP for a list of supported features and usage instructions.
Establishes or returns the TCP connection to the SMTP server.
If we had a host, we'll connect directly.
If we have a domain, then we'll do an MX lookup on it.
If we don't have either, you'll probably just see errors or unresolved futures.
Returns the Future representing the connection. Attach events via methods on Future such as on_done, then etc.
on_done
then
See also: "connected"
Looks up MX records for the given domain.
Returns a Future which will resolve to the list of records found.
Overrides IO::Async::Notifier configure to apply SMTP-specific config.
configure
Returns the Future indicating our SMTP connection.
Resolves to a Net::Async::SMTP::Connection instance on success.
Returns any defined SSL parameters as passed to the constructor or "configure".
Attempts login, connecting first if required.
Returns a Future which will resolve with this instance when the login completes.
Attempts to send message(s), connecting first if required.
If this server requires login, you'll need to call "login" yourself.
See "send" in Protocol::SMTP::Client.
Returns a Future.
Quit the SMTP connection, unsetting the connection.
Returns the port used for communicating with the server, or undef for default (25).
Returns the host we're going to connect to.
Returns the domain used for the email server.
Returns the auth method used for server authentication.
add_child, adopt_future, adopted_futures, can_event, children, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2012-2024. Licensed under the same terms as Perl itself.
To install Net::Async::SMTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::SMTP
CPAN shell
perl -MCPAN -e shell install Net::Async::SMTP
For more information on module installation, please visit the detailed CPAN module installation guide.