Agent-TCLI-Package-Net
view release on metacpan or search on metacpan
lib/Agent/TCLI/Package/Net/SMTP.pm view on Meta::CPAN
manual: >
This holds the sender's email address.
type: Param
---
Agent::TCLI::Parameter:
name: to
constraints:
- EMAIL_LOOSE
help: The recipiants email address
manual: >
This holds a list of recipients. Note that To/CC/BCC fields are separated
in your email body. From the SMTP server's point of view
(and from this component's too) there is no difference as
who is To, who CC and who BCC.
The bottom line is: be careful how you construct your email message.
type: Param
---
Agent::TCLI::Parameter:
name: body
help: the body of the email
manual: >
The textual part of hte email message, or the MIME content if so inclined.
type: Param
---
Agent::TCLI::Parameter:
name: subject
aliases: subj
help: the subject line
manual: >
The subject line for the message.
type: Param
---
Agent::TCLI::Parameter:
name: server
default: localhost
help: The SMTP server to use.
manual: >
The name or address of the mail server that will accept delivery or relay
the mail message.
type: Param
---
Agent::TCLI::Parameter:
name: port
help: Port SMTP server is listening on
constraints:
- UINT
class: numeric
default: 25
manual: >
Sometimes, SMTP servers are set to listen to other ports,
in which case you need to set this parameter to the correct
value to match your setup.
type: Param
---
Agent::TCLI::Parameter:
name: timeout
constraints:
- UINT
class: numeric
default: 30
help: Timeout in seconds
manual: >
The timeout in seconds for the SMTP transaction. The default is 30 seconds.
type: Param
---
Agent::TCLI::Parameter:
name: textfile
constraints:
- ASCII
help: A file of plain text for the message body.
manual: >
The textfile will be used as the message body for sending an email. It
should not include headers. If the file cannot be found, the request will
fail. Use Unix style path names.
type: Param
---
Agent::TCLI::Parameter:
name: msgfile
constraints:
- ASCII
help: A file of plain text for the message body.
manual: >
The msgfile will be used as the entire message for sending an email. It
should include headers. If the file cannot be found, the request will
fail. Use Unix style path names. The to and from must still be defined,
though they need not match what is in the msg.
type: Param
---
Agent::TCLI::Command:
name: smtp
call_style: session
command: tcli_smtp
contexts:
ROOT: smtp
handler: establish_context
help: smtp client to send mail
manual: >
Send mail to aSMTP server
topic: net
usage: smtp send to=joe@example.com from=jane@example.com subject=Hi body="hi"
---
Agent::TCLI::Command:
name: send
call_style: session
command: tcli_smtp
contexts:
smtp: send
handler: send
help: send a mail message
manual: >
Send mail to a SMTP server. There are many parameters that are required to
properly construct the message.
parameters:
to:
from:
body:
timeout:
subject:
server:
port:
required:
lib/Agent/TCLI/Package/Net/SMTP.pm view on Meta::CPAN
$email = Email::Simple->create(
header => [
From => $param->{'from'},
To => $param->{'to'},
Subject => $param->{'subject'},
],
body => $param->{'body'},
);
$body = $email->as_string;
}
elsif ($command eq 'sendtext')
{
my $file = read_file( $param->{'textfile'}, err_mode => 'quiet' );
unless (defined $file)
{
$request->Respond($kernel, "failed: sendtext file not found", 404);
$self->Verbose("send: sendtext file not found (".$param->{'textfile'}.") ");
return
}
$email = Email::Simple->create(
header => [
From => $param->{'from'},
To => $param->{'to'},
Subject => $param->{'subject'},
],
body => $file,
);
$body = $email->as_string;
}
elsif ($command eq 'sendmsg')
{
my $file = read_file( $param->{'msgfile'}, err_mode => 'quiet' );
unless (defined $file)
{
$request->Respond($kernel, "failed: sendmsg file not found", 404);
$self->Verbose("send: sendmsg file not found (".$param->{'textfile'}.") ");
return
}
$body = $file;
}
# Note that you are prohibited by RFC to send bare LF characters in e-mail
# messages; consult: http://cr.yp.to/docs/smtplf.html
$body =~ s/\n/\r\n/g;
POE::Component::Client::SMTP->send(
# Email related parameters
From => $param->{'from'},
To => $param->{'to'},
Body => $body,
# server params
Port => $param->{'port'},
Server => $param->{'server'},
Timeout => $param->{'timeout'},
# POE related parameters
Context => $request,
Alias => 'pococlsmtpX',
SMTP_Success => 'SendMailSuccess',
SMTP_Failure => 'SendMailFailure',
# Debug => 0,
);
}
=item show
This POE event handler executes the show commands.
=back
=cut
1;
#__END__
=head3 INHERITED METHODS
This module is an Object::InsideOut object that inherits from Agent::TCLI::Package::Base. It
inherits methods from both. Please refer to their documentation for more
details.
=head1 AUTHOR
Eric Hacker E<lt>hacker at cpan.orgE<gt>
=head1 BUGS
SHOULDS and MUSTS are currently not enforced.
Test scripts not thorough enough.
Probably many others.
=head1 LICENSE
Copyright (c) 2007, Alcatel Lucent, All rights resevred.
This package is free software; you may redistribute it
and/or modify it under the same terms as Perl itself.
=cut
( run in 0.615 second using v1.01-cache-2.11-cpan-39bf76dae61 )