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 7308
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 => " "
-
});
-
-
}
-
-
numberwhun 3,509
Recognized Expert Moderator Specialist
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
numberwhun 3,509
Recognized Expert Moderator Specialist
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |