[Home]UseSendMail

UseModWiki | RecentChanges | Preferences

Using sendmail.pm for sending e-mail

As sendmail did not work on my Win XP installation I replaced this by using the sendmail.pm module. This requires that you have installed this module somewhere in you lib path (e.g. from http://search.cpan.org/~mivkovic/ or http://alma.ch/perl/mail.html).

Changes are as follows:

...
package UseModWiki;

use Mail::Sendmail; # change wk 10.02.2003

use strict;

...

use vars qw(@RcDays @HtmlPairs @HtmlSingle
  $TempDir $LockDir $DataDir $HtmlDir $UserDir $KeepDir $PageDir
...
  $UserGotoBar $mailserver); # change wk 10.02.2003

...
$mailserver = "mail.xxxx.com";  # change default e-mail server - wk 10.02.2003
...

and:

# change wk 10.02.2003 - start
# Translation note: the email messages are still sent in English
sub SendEmail {
  my ($to, $from, $reply, $subject, $message) = @_;
    ### debug
    ## print "Content-type: text/plain\n\n";
    ## print " to: '$to'\n";
    ## return;
  # sendmail options:
  #    -odq : send mail to queue (i.e. later when convenient)
  #    -oi  : do not wait for "." line to exit
  #    -t   : headers determine recipient.
#  open (SENDMAIL, "| $SendMail -oi -t ") or die "Can't send email: $!\n";
#  print SENDMAIL <<"EOF";
#From: $from
#To: $to
#Reply-to: $reply
#Subject: $subject\n
#$message
#EOF
#  close(SENDMAIL) or warn "sendmail didn't close nicely";
#  
	my %mail;
	$mail{From}    = $from;
	$mail{To}      = $to;
	$mail{Smtp}    = $mailserver;
	$mail{Subject} = $subject;
	$mail{body}    = "$message";
	if (sendmail(%mail) )
	{
		open EMAIL, ">>$DataDir/emailsent.txt";
		print  EMAIL "sendmail SUCCESS: $from >> $to >> $mailserver >> $subject\n"; # print MESS "\nSend Email Error!\n$Mail::Sendmail::error";
		close EMAIL;	}
	else
	{ 
		open EMAIL, ">>$DataDir/emailsent.txt";
		print  EMAIL "sendmail FAILURE $Mail::Sendmail::error: $from >> $to >> $mailserver >> $subject\n";
		close EMAIL;
	}
}

# end wk

Klemens Waldhör (dr.klemens.waldhoer@waldhor.com)


UseModWiki | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited December 23, 2004 10:55 am by 65.125.63.81.cust.bluewin.ch (diff)
Search: