NAME

Net::Async::SMTP::Client - sending email with IO::Async

SYNOPSIS

#!/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;

DESCRIPTION

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.

METHODS

connection

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.

See also: "connected"

mx_lookup

Looks up MX records for the given domain.

Returns a Future which will resolve to the list of records found.

configure

Overrides IO::Async::Notifier configure to apply SMTP-specific config.

connected

Returns the Future indicating our SMTP connection.

Resolves to a Net::Async::SMTP::Connection instance on success.

ssl_parameters

Returns any defined SSL parameters as passed to the constructor or "configure".

login

Attempts login, connecting first if required.

Returns a Future which will resolve with this instance when the login completes.

send

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

Quit the SMTP connection, unsetting the connection.

Returns a Future.

METHODS - Accessors

port

Returns the port used for communicating with the server, or undef for default (25).

host

Returns the host we're going to connect to.

domain

Returns the domain used for the email server.

auth

Returns the auth method used for server authentication.

INHERITED METHODS

IO::Async::Notifier

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

AUTHOR

Tom Molesworth <TEAM@cpan.org>

LICENSE

Copyright Tom Molesworth 2012-2024. Licensed under the same terms as Perl itself.