468,554 Members | 1,418 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

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 10135
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,503 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,503 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

Post your reply

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

Similar topics

15 posts views Thread by Sven Templin | last post: by
121 posts views Thread by typingcat | last post: by
8 posts views Thread by Carl | last post: by
2 posts views Thread by krash88 | last post: by
5 posts views Thread by ibid | last post: by
31 posts views Thread by happyse27 | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.