473,511 Members | 11,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to - Net::SMTP with user name & password

7 New Member
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.
Jul 23 '08 #1
5 7308
jain236
36 New Member
Hi you can try this one to send mail
Expand|Select|Wrap|Line Numbers
  1.  use Mail::Sender;
  2. sub sendEmail
  3. {    
  4.     my $mailmsg =shift;    
  5.     my $sender = new Mail::Sender {from => ''}; 
  6.  
  7. $sender->MailMsg(
  8. {   
  9.     smtp => '',
  10.     to      => [email],
  11.     subject => "",
  12.     msg => " "
  13. });
  14.  
  15. }    
  16.  
  17.  
Jul 23 '08 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi you can try this one to send mail
Expand|Select|Wrap|Line Numbers
  1.  use Mail::Sender;
  2. sub sendEmail
  3. {    
  4.     my $mailmsg =shift;    
  5.     my $sender = new Mail::Sender {from => ''}; 
  6.  
  7. $sender->MailMsg(
  8. {   
  9.     smtp => '',
  10.     to      => [email],
  11.     subject => "",
  12.     msg => " "
  13. });
  14.  
  15. }    
  16.  
  17.  
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
Jul 23 '08 #3
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:

Expand|Select|Wrap|Line Numbers
  1. $smtp->auth(uname, pwd);
  2.  
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
Jul 23 '08 #4
veralee
7 New Member
Thanks lovely people. Well here's the code I'm working with:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Net::SMTP;
  4.  
  5. print "content-type: text/html\n\n <center>start, using: mailhost<br>";
  6.  
  7. &domail;
  8.  
  9. print "done</center>";
  10.  
  11. sub domail {
  12.     print "in domail<br>";
  13.     $smtp = Net::SMTP->new(mailhost);
  14.     unless($smtp) {
  15.         print "smtp failed<br>";
  16.         exit;
  17.     }
  18.     unless( $smtp->auth('uname', 'upass') ) { # ** <- fails here
  19.         print "auth failed<br>";
  20.         exit;
  21.     }
  22.  
  23.     $smtp->mail("fromaddr");
  24.     $smtp->recipient("toaddr");
  25.  
  26.     $smtp->data;
  27.     $smtp->datasend("From: fromaddr");
  28.     $smtp->datasend("To: toaddr");
  29.     $smtp->datasend("Subject: This is a test");
  30.     $smtp->datasend("\n");
  31.     $smtp->datasend("blahblah");
  32.     $smtp->dataend;
  33.     $smtp->quit;
  34. }
  35.  
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.
Jul 24 '08 #5
veralee
7 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Net::SMTP;
  4.  
  5. print "content-type: text/html\n\n";
  6. &domail; # send the mail - normally pass info but here just call it
  7. print "done";
  8.  
  9. sub domail {
  10.     $smtp = Net::SMTP->new('mail.host.com'); 
  11.     unless($smtp) {
  12.         print "smtp failed<br>";
  13.         exit;
  14.     }
  15.  
  16.     $smtp->auth('user_name', 'user_password');
  17.  
  18.     $smtp->mail('me@here.com');
  19.     $smtp->recipient('them@there.com');
  20.  
  21.     $smtp->data;
  22.     $smtp->datasend('From: sender name <me@here.com>'."\n");
  23.     $smtp->datasend('To: recip name <them@there.com>'."\n");
  24.     $smtp->datasend("Subject: This is a test\n");
  25.     $smtp->datasend("\n");
  26.     $smtp->datasend("blahblah etc");
  27.     $smtp->dataend;
  28.     $smtp->quit;
  29. }
  30.  
Thanks to all who considered my problem.
Jul 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3051
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...
2
13692
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...
0
1319
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?
3
1176
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...
1
1807
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...
4
2351
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 =...
13
6777
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...
5
5286
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...
1
2673
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...
0
7251
marktang
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,...
0
7148
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...
0
7367
Oralloy
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,...
1
7089
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...
0
7517
tracyyun
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...
1
5072
isladogs
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...
0
3230
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...
0
1581
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 ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.