Question
While sending new user registration confirmation mail, Net:SMTP fails as my mail server requires TLS. Here is the output from the error log (I have changed some details to hide personal details):
Net::SMTP>>> Net::SMTP(2.30)
Net::SMTP>>> Net::Cmd(2.27)
Net::SMTP>>> Exporter(5.58)
Net::SMTP>>> IO::Socket::INET(1.31)
Net::SMTP>>> IO::Socket(1.30)
Net::SMTP>>> IO::Handle(1.27)
Net::SMTP=GLOB(0x8cfa570)<<< 220 mail.server.com Microsoft ESMTP MAIL Service, Version: xxxx ready at Wed, 28 Feb 2007 18:32:45 +0530
Net::SMTP=GLOB(0x8cfa570)>>> EHLO mail.host
Net::SMTP=GLOB(0x8cfa570)<<< 250-mail.host Hello [xxx.xxx.xxx.xxx]
Net::SMTP=GLOB(0x8cfa570)<<< 250-TURN
Net::SMTP=GLOB(0x8cfa570)<<< 250-SIZE
Net::SMTP=GLOB(0x8cfa570)<<< 250-ETRN
Net::SMTP=GLOB(0x8cfa570)<<< 250-PIPELINING
Net::SMTP=GLOB(0x8cfa570)<<< 250-DSN
Net::SMTP=GLOB(0x8cfa570)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x8cfa570)<<< 250-8bitmime
Net::SMTP=GLOB(0x8cfa570)<<< 250-BINARYMIME
Net::SMTP=GLOB(0x8cfa570)<<< 250-CHUNKING
Net::SMTP=GLOB(0x8cfa570)<<< 250-VRFY
Net::SMTP=GLOB(0x8cfa570)<<< 250-TLS
Net::SMTP=GLOB(0x8cfa570)<<< 250-STARTTLS
Net::SMTP=GLOB(0x8cfa570)<<< 250-X-EXPS GSSAPI NTLM
Net::SMTP=GLOB(0x8cfa570)<<< 250-AUTH GSSAPI NTLM
Net::SMTP=GLOB(0x8cfa570)<<< 250-X-LINK2STATE
Net::SMTP=GLOB(0x8cfa570)<<< 250-XEXCH50
Net::SMTP=GLOB(0x8cfa570)<<< 250 OK
Net::SMTP=GLOB(0x8cfa570)>>> MAIL FROM:<xxx@my.company.com>
Net::SMTP=GLOB(0x8cfa570)<<< 530 5.7.0 Must issue a STARTTLS command first
After this I get the error page stating that there was an internal problem sending mail and user is not registered.
What can I do to enable TLS option while connecting to the mail server.
Environment
--
RajatAgrawal - 28 Feb 2007
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
Sorry, you will have to write some code to do it. The code that sends mail is all in lib/TWiki/Net.pm. WHen you have fixed it, please contribute it back!
--
CrawfordCurrie - 14 Mar 2007
My Hack
I had it figured out after a night of trying various options. Since I had a time crunch the following hack worked for me.
I used Michal Ludvig's
smtp-client script for sending mail. I could not get sendmail to work properly also the perl module (
Net::SMTP::TLS) based on the above script required learning more perl than I could in one night, I am just a plain C guy, but i am sure someone can integrate it elegantly.
I changed the routine _sendEmailBySendMail, here is the diff -C 5:
*** Net.pm 2007-03-02 14:06:14.000000000 +0530
--- Net.pm.original 2007-03-01 11:36:55.000000000 +0530
***************
*** 273,357 ****
sub _sendEmailBySendmail {
my( $this, $text ) = @_;
# send with sendmail
my ( $header, $body ) = split( "\n\n", $text, 2 );
- $header =~ s/\nBCC\:[^\n]*//os; #remove BCC line from header
- my @headerlines = split( /\r?\n/, $header );
$header =~ s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
$text = "$header\n\n$body"; # rebuild message
! # extract @to from 'To:', 'CC:', 'BCC:'
! my @to = ();
! my $from = '';
!
! # extract 'From:'
! my @arr = grep( /^From: /i, @headerlines );
! my $user = '';
! my $server = '';
! if( scalar( @arr ) ) {
! $from = $arr[0];
! $from =~ s/^From:\s*//io;
! $from =~ s/.*<(.*?)>.*/$1/o; # extract "user@host" out of "Name <user@host>"
!
! ($user, $server) = ($from =~ /^(\S*)@(\S*)/);
! $from = $user.'@'.$server;
! }
! unless( $from ) {
! # SMELL: should be a TWiki::inlineAlert
! die "ERROR: Can't send mail, missing 'From:'";
! }
!
! @arr = grep( /^To: /i, @headerlines );
! my $tmp = '';
! if( scalar( @arr ) ) {
! $tmp = $arr[0];
! $tmp =~ s/^To:\s*//io;
! @arr = split( /,\s*/, $tmp );
! push( @to, @arr );
! }
! @arr = grep( /^CC: /i, @headerlines );
! if( scalar( @arr ) ) {
! $tmp = $arr[0];
! $tmp =~ s/^CC:\s*//io;
! @arr = split( /,\s*/, $tmp );
! push( @to, @arr );
! }
! @arr = grep( /^BCC: /i, @headerlines );
! if( scalar( @arr ) ) {
! $tmp = $arr[0];
! $tmp =~ s/^BCC:\s*//io;
! @arr = split( /,\s*/, $tmp );
! push( @to, @arr );
! }
! if( ! ( scalar( @to ) ) ) {
! # SMELL: should be a TWiki::inlineAlert
! die "ERROR: Can't send mail, missing recipient";
! }
!
! return undef unless( scalar @to );
!
! # Change SMTP protocol recipient format from
! # "User Name <userid@domain>" to "userid@domain"
! # for those SMTP hosts that need it just that way.
! foreach (@to) {
! s/^.*<(.*)>$/$1/;
! }
!
! my $recpt = '';
! foreach (@to) {
! ($user, $server) = ($_ =~ /^(\S*)@(\S*)/);
! $_ = $user.'@'.$server;
! $recpt = $recpt . ' --to ' . $_;
! }
!
! my $MailCommand = $TWiki::cfg{MailProgram}.' --verbose --host=xxx.xxx.com --user='."$TWiki::cfg{SMTP}{Username}".' --password='."$TWiki::cfg{SMTP}{Password}".' --enable-auth --from='.$from.$recpt.' --data=-';
!
! open( MAIL, '|'.$MailCommand.'>Net.pm.log' ) ||
die "ERROR: Can't send mail using TWiki::cfg{MailProgram}";
print MAIL $text;
-
close( MAIL );
die "ERROR: Exit code $? from TWiki::cfg{MailProgram}" if $?;
}
--- 273,288 ----
sub _sendEmailBySendmail {
my( $this, $text ) = @_;
# send with sendmail
my ( $header, $body ) = split( "\n\n", $text, 2 );
$header =~ s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
$text = "$header\n\n$body"; # rebuild message
! open( MAIL, '|'.$TWiki::cfg{MailProgram} ) ||
die "ERROR: Can't send mail using TWiki::cfg{MailProgram}";
print MAIL $text;
close( MAIL );
die "ERROR: Exit code $? from TWiki::cfg{MailProgram}" if $?;
}
Most of the code was copied from the other routine _sendEmailByNetSMTP(), i hard coded the mail server since if u specify it in the configuration then Net:SMTP is used instead of the external program. The hardest thing I had to figure out was how to get an @ into the email id array without it being interpreted by perl. This is what i found on the Internet and it helped some without really providing an answer -
http://www.thescripts.com/forum/thread50597.html
. So i am still not clear with the whole @ thing
--
RajatAgrawal - 19 Mar 2007