473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Email Using Perl in Windows

3
I'm tyring to write something that will send a simple email using Perl

so far this is what I have
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3.  
  4. my $executable = "saplotus.exe';
  5. my $server = 'test@domain';
  6. my $from = 'aetinti@gmail.com';
  7. my $to = 'aetinti@gmail.com';
  8. my $subject = 'Test: Perl system call';
  9. my $body = "Test: Perl system call";
  10.  
  11. my @args = (  "$executable", "-server", "$server", 
  12.                      "-from", "$from", 
  13.                      "-to", "$to", 
  14.                      "-subject", "\"$subject\"", 
  15.                      "-body", "\"$body\""
  16.                   );
  17. my $result = system(@args);
  18. print "$result";
  19.  
I also have the following but as I now understand I can't use this unless in Unix
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use CGI;
  3.  
  4. my $query    = new CGI;
  5. my $sendmail = "/usr/sbin/sendmail -t";
  6. my $reply_to = "Reply-to: aetinti@gmail.com";
  7. my $subject  = "Subject: Confirmation of your submission";
  8. my $content  = "Thanks for your submission.";
  9. my $to       = $query -> param('send_to');
  10. my $file     = "subscribers.txt";
  11.  
  12. unless ($to) {
  13.   print $query->header;
  14.   print "Please fill in your email and try again";
  15. }
  16.  
  17. open (FILE, ">>$file") or die "Cannot open $file: $!";
  18. print $to,"\n";
  19. close(FILE); 
  20.  
  21. my $send_to  = "To: ". $query->param('send_to');
  22.  
  23. open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
  24. print SENDMAIL $reply_to;
  25. print SENDMAIL $subject;
  26. print SENDMAIL $to;
  27. print SENDMAIL "Content-type: text/plain\n\n";
  28. print SENDMAIL $content;
  29. close(SENDMAIL);
  30.  
  31. print $query->header;
  32. print "Confirmation of your submission will be emailed to you.";
  33.  
I know there's a way to get sendmail to work with windows I just haven't been able to figure it out ... can someone help me fix this script or offer on that will work? thank you
Jan 11 '07 #1
6 10520
BobVDP
4
Use this...
Expand|Select|Wrap|Line Numbers
  1. #!C:\Perl\bin\perl.exe
  2.  
  3. use Net::SMTP;
  4.  
  5. my $relay='name-of-your-smtp-mailserver-here';
  6. my $to='whoever@wherever.org';
  7. my $from='you@yourdomain.org';
  8. my $file='your_file.html';
  9.  
  10. open(FILE,"$file");
  11. @body=<FILE>;
  12.  
  13. my $smtp = Net::SMTP->new($relay) || die "Did Not Connect\n" if !($smtp);
  14.  
  15. $smtp->mail($from);         # use the sender's address here
  16. $smtp->to($to);              # recipient's address
  17. $smtp->data();                              # Start the mail
  18.  
  19. # Send the header.
  20. $smtp->datasend("To: $to\n");
  21. $smtp->datasend("From: $from\n");
  22. $smtp->datasend("Content-type: text/html\n\n");
  23.  
  24. # Send the body.
  25. $smtp->datasend(@body);
  26. $smtp->dataend();                           # Finish sending the mail
  27. $smtp->quit;                                # Close the SMTP connection
  28.  
Jan 12 '07 #2
atinti
3
Thanks, it's not connecting but it compiles :) one battle down one to do ... I may not be able to connect to google this way anymore which may be the problem. Thanks Again for all you help
Jan 12 '07 #3
Merv
1
BobVDP,

Thanks for your post it was a real help for me! I got the script to connect by using the SMTP server IP addres, not the server name.

Thanks,

Merv
Oct 19 '08 #4
numberwhun
3,509 Expert Mod 2GB
Atinti and BobVDP,

You really need to please use code tags whenever you post code in the forums. They are required and are mentioned in the Posting Guidelines, which you should have already read. If not, please do so.

If you don't add them, us Moderators need to clean up behind you and we really prefer you add them when you post.

Thank you!

Regards,

Jeff
(Perl Forum Leader)
Oct 19 '08 #5
eWish
971 Expert 512MB
The OP made this post over a year ago. I am willing to bet they may not get the warning message.

--Kevin
(peon moderator) :)
Oct 19 '08 #6
numberwhun
3,509 Expert Mod 2GB
The OP made this post over a year ago. I am willing to bet they may not get the warning message.

--Kevin
(peon moderator) :)
You know, I (again) didn't think to look at the dates. You would think that I would learn.

Merv: You need to respond to newer posts. Not that the older posts don't deserve an answer, but if they haven't posted regarding the issue in that long then they either fixed the issue or don't care.

Regards,

Jeff
Oct 19 '08 #7

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

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
8
by: Carl | last post by:
Hi, Using MS Access 2000, is it possible to run a UPDATE or INSERT SQL query using some form of conditional IF THEN ?? for example: SELECT * FROM Books IF EXISTS(Select Books.ID = 1)
6
by: Doomster | last post by:
In a previous job, we had Perl scripts which could interact with a SQL DB using Perl's DBI module We were able to programmatically add, delete and query tables using this module. Is it possible...
2
by: krash88 | last post by:
I'm as new as it gets to PERL and have been going over a few scripts for an NT server that I run. One of which sends an email to registered users using SMTP. It seems to connect with SMTP server...
5
by: ibid | last post by:
hi every one just wondering if anyone could help sorry if i seem abit dumb but im a newbie to it all ive got to asign a mail program on my auction site in the config.pl files (i think this is the...
1
by: Ant | last post by:
Hello! I am looking for a good hardcopy Perl book for newbies/beginners (including myself) who use Windows (not UNIX/Linux) and that isn't so old. After talking to my Linux friends who use Perl,...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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...
0
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...

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.