473,385 Members | 1,570 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,385 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 10519
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.