Need to send email via SMTP server that has username and password. Using MIME::Entity which uses smtpsend. The problem is I don't know how to pass the package the username and password. When I omit the "auth" line and use an SMTP server that does not require authentication this works like a charm.
sub sSendEmailMIME {
use Mail::Internet;
use MIME::Entity;
my $retval = 0;
my ($to,$from,$subject,$with,$encoding,$filename) = @_;
if ( my $msg = MIME::Entity->build(From => $from,
To => $to,
Subject => $subject,
Type => 'text/html',
Encoding => "7bit",
Path => "$filename",
Filename => "$filename") ) {
if ( $msg->smtpsend(Host => 'smtp.whatever.net') ) {
$msg->auth ('me@whatever.net','123abc');
$retval = 1;
print "sent\n";
} else {
print "send FAILED: $!\n";
}
}
return $retval;
}
This invariably gives me a "send FAILED" without explanation.
Thanks for your help.
Gary
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|