I'm in dire need to use Net::SMTP. The server no longer uses "sendmail". I found an example of using Net::SMTP but I have to also include a user name and password for the server. The host provided that, and I discovered that the method call is, auth ( USERNAME, PASSWORD ). But I don't know where to put that call. The host isn't into Perl and I'm on my own about this.
Could someone be so extremely kind as to show me a simple example of sending email (no attachment) with Net::SMTP along with providing the user name and password in the code? I have a little understanding of basic Perl and "sendmail" made life easy. But now... egads... the good old days are gone.
Thanks to any kind soul.
5 7275
Hi you can try this one to send mail -
use Mail::Sender;
-
sub sendEmail
-
{
-
my $mailmsg =shift;
-
my $sender = new Mail::Sender {from => ''};
-
-
$sender->MailMsg(
-
{
-
smtp => '',
-
to => [email],
-
subject => "",
-
msg => " "
-
});
-
-
}
-
-
Hi you can try this one to send mail -
use Mail::Sender;
-
sub sendEmail
-
{
-
my $mailmsg =shift;
-
my $sender = new Mail::Sender {from => ''};
-
-
$sender->MailMsg(
-
{
-
smtp => '',
-
to => [email],
-
subject => "",
-
msg => " "
-
});
-
-
}
-
-
Unfortunately, since the OP specified that they have a username and password setup for accessing the email, this doesn't solve their problem. They are actually on the right path.
Regards,
Jeff
You should take a look at the CPAN documentation for Net::SMTP as it is pretty good, but in my opinion, does lack examples of where to put stuff, I understand that.
Personally, I would define my new constructor and then right after that put the auth line, as so:
Also, here is a page with examples of how to use this module as well.
If I were you, I would write it up and try to get it to work. If you have issues, post your code here (enclosed in code tags) and we will try and help you get it working.
Regards,
Jeff
Thanks lovely people. Well here's the code I'm working with: -
#!/usr/bin/perl
-
-
use Net::SMTP;
-
-
print "content-type: text/html\n\n <center>start, using: mailhost<br>";
-
-
&domail;
-
-
print "done</center>";
-
-
sub domail {
-
print "in domail<br>";
-
$smtp = Net::SMTP->new(mailhost);
-
unless($smtp) {
-
print "smtp failed<br>";
-
exit;
-
}
-
unless( $smtp->auth('uname', 'upass') ) { # ** <- fails here
-
print "auth failed<br>";
-
exit;
-
}
-
-
$smtp->mail("fromaddr");
-
$smtp->recipient("toaddr");
-
-
$smtp->data;
-
$smtp->datasend("From: fromaddr");
-
$smtp->datasend("To: toaddr");
-
$smtp->datasend("Subject: This is a test");
-
$smtp->datasend("\n");
-
$smtp->datasend("blahblah");
-
$smtp->dataend;
-
$smtp->quit;
-
}
-
For the 'new' call I really am using "mailhost", and that seems to work, although I have yet to hear from the host if that's right. But I do get a value returned for $smpt on that. I removed actual username and password and email addresses here, but used valid info for the test.
Where it fails is after the attempt to do the authorization. The returned web page looks like this,
start, using: mailhost
in domail
auth failed
I'm not sure if I need to do the auth() after getting $smtp or maybe it should be,
Net::SMTP auth()
Thanks for this link, it was some help. CPAN is pretty frail in the realm of examples.
Eureka!!!!
My bad. I was checking the return value for the auth() method... and there isn't any. I should have read the CPAN more closely. Odd that there is no ok/fail indication of authendication. Anyway, in case anyone else needs to know, here's what works.
This is in a very crude form.. no checks and not passing anything to the sub, just "hard wired" for the test. -
#!/usr/bin/perl
-
-
use Net::SMTP;
-
-
print "content-type: text/html\n\n";
-
&domail; # send the mail - normally pass info but here just call it
-
print "done";
-
-
sub domail {
-
$smtp = Net::SMTP->new('mail.host.com');
-
unless($smtp) {
-
print "smtp failed<br>";
-
exit;
-
}
-
-
$smtp->auth('user_name', 'user_password');
-
-
$smtp->mail('me@here.com');
-
$smtp->recipient('them@there.com');
-
-
$smtp->data;
-
$smtp->datasend('From: sender name <me@here.com>'."\n");
-
$smtp->datasend('To: recip name <them@there.com>'."\n");
-
$smtp->datasend("Subject: This is a test\n");
-
$smtp->datasend("\n");
-
$smtp->datasend("blahblah etc");
-
$smtp->dataend;
-
$smtp->quit;
-
}
-
Thanks to all who considered my problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Almir |
last post by:
I hate this Net::SMTP stuff, everything works fine but for the suject
field. I see no way of having it show in an email when sent. Has
anyone had this problem, can anyone explain why there are no...
|
by: RandRace |
last post by:
I'm having some problems with a little script i wrote using net::smtp.
I originally wrote it in linux where it works perfectly. I tried to
use it from windows the other day and it doesn't work. It...
|
by: peterson |
last post by:
I was trying to send asp.net-smtp mail of UTF-8 unicode
international character contents. When I opened the
mailbox contents was broken. I am using html format too.
Am I missing something?
|
by: Chris |
last post by:
Is the following assumption correct?
-ASP.NET user does not see the local drives I have mapped
If so how can I get it to notice the mapped drives? Do I need to change the
user in the...
|
by: neog |
last post by:
I'm having a problem with Net::Smtp. Does the datasend() method have problems sending strings containing single quotes?
Like I stored the string "Germany's biggest bank, hired" in a hash and it...
|
by: patrickinminneapolis |
last post by:
Hi guys,
I'm trying to write an emailer, but I can't manage to construct the object properly. Here's what I've got:
#!/usr/local/bin/perl -w
use Net::SMTP;
$smtp =...
|
by: jcor |
last post by:
Hi, I'm trying some code to send a mail with my script. This is it:
#!/usr/bin/perl
use Net::SMTP;
my $smtp_server='62.193.245.15';
my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open...
|
by: jimhill10 |
last post by:
I have a perl script that creates an email attachment file from POST data on a web page. This works just fine. I want to customize the email body to contain all of the text data from the file...
|
by: wootmaster |
last post by:
I'm writing a script that will run a few tests on a given mail server, it's meant to test to see if VRFY and EXPN is enabled or not. However, when I use "verify" to test to see if VRFY is enabled on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |