473,670 Members | 2,307 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 7334
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
3058
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 documentations on smtp or better ones at least. I just need the subject field to show. $smtp = Net::SMTP->new('some.your.com'); $smtp->mail ($mailfrom); #the administrator's email goes here $smtp->to('mine@your.com');
2
13700
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 connects to the server and prints the banner but will not send mail. Here is my script: use Net::SMTP; my $smtp = Net::SMTP->new('smtp.comcast.net') or die "Can't Open server"!";
0
1327
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
1180
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 machine.config? Thanks Chris
1
1820
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 prints out fine when i retrieve the scalar value. But i do datasend($msg) and when i open the email I see something like "Germany's bigges! t bank, hired". These "!" are popping all over the place. Any thoughts would be greatly appreciated.
4
2365
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 = Net::SMTP->new('mailhost'); print $smtp->domain,"\n"; $ perl mailer.txt Can't call method "domain" on an undefined value at mailer.txt line 6.
13
6794
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 server\n"; $smtp->mail('joao.correia@tvn.pt'); $smtp->to('jcor@sapo.pt'); $smtp->auth("joao.correia@tvn.pt","*password*");
5
5297
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 itself. I thought this would be just a matter of using the $smtp->datasend($POSTvalues) with the $values coming from the names on the web page posting the data. Can someone show me what the correct code snippet would be? Here is my code: ...
1
2690
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 the given host, if VRFY is disabled on the server the "verify" function will still return true/1. I used the Debug function to check, and it shows that VRFY is disabled on the mail server. Is there a reason or a way around this? snippet of...
0
8469
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.