Tags:
create new tag
view all tags

Question

I use a Debian server on which the mail system is not configured. Insead I want to send mail using Net::SMTP. SMTPMAILHOST is set to some smtp server which I want to use. This smtp server requires authentication.

When a user registers in the wiki, the confirmation page says "couldn't send mail becuase server requires authentication".

How do I configure the authentication for the smtp mail server?

  • TWiki version: TWiki20021230beta.zip
  • Perl version: 5.6
  • Web server & version: Apache 1.x
  • Server OS: Debian
  • Web browser & version: Mozilla
  • Client OS: Debian

-- FrankGerhardt - 17 Jan 2003

Answer

This isn't currently supported, but it should not be too hard to add this if you know Perl, or can learn it (PerlTips has pointers).

Using Net::SMTP, you'll need to read http://perlmonks.thepen.com/110334.html this Perlmonks article and install the Net::SMTP_auth package it mentions, and then edit the last subroutine in CVS:lib/TWiki/Net.pm to authenticate suitably. It would be best to create a TWiki.cfg variable for the SMTP auth password. I haven't done this myself, but the article looks good.

If you do get this working, please submit a patch using the PatchGuidelines as it would be generally useful.

There may be a simpler way of doing this using sendmail, but Net::SMTP would be useful for more platforms.

-- RichardDonkin - 19 Jan 2003

Turns out that Perl 5.8 and above has a later version of Net::SMTP that includes authentication.

The following is what I tried as a hack. It did not work:

  1. Find and install Authen::SASL which is the generalised LDAP authentication needed by Net::SMTP
  2. In TWiki/Net.pm I added the bit in bold

    my $smtp = 0;                                                               
    if( $helloHost ) {                                                          
        $smtp = Net::SMTP->new( $mailHost, Hello => $helloHost );               
    } else {                                                                    
        $smtp = Net::SMTP->new( $mailHost );                                    
    }                                                                           
   $smtp -> auth('mrjcleaver', 'mypassword');                              
    my $status = ($smtp->ok() ? "" : "ERROR: Can't authenticate using Net::SMTP 
". $smtp->message);                                                             
    return $status;                                                             
    my $status = "";                                                            
    if ($smtp) {   

It failed because the status always failed, but I think it is the right approach.

Then I realised that I could use sendmail instead of Net::SMTP so I made that work instead.

HOH, M.

-- MartinCleaver - 28 Mar 2003

You could of course just upgrade the Net::SMTP in a pre-5.8 Perl installation, using perl -MCPAN -e shell and install Net::SMTP.

-- RichardDonkin - 29 Mar 2003

The above suggestions do not work circa January 2008 and the bug reporting system is closed to new users... What follows is a very quick stab at it without really understanding the rest of twiki's code base. I would appreciate any feedback.. All code copyright 2007, Michael Papet and published under the GPL version 2 or later license.

1. Find and open Net.pm

2. Include MIME::Base64 on the top of Net.pm. (It won't work without it!)

3. towards the bottom of the file is where the disfunctional code is. Find the start by searching for if( $TWiki::cfg{SMTP}{Username} ) {

4. Comment out the following line. # $smtp->auth($TWiki::cfg{SMTP}{Username}, $TWiki::cfg{SMTP}{Password});

5.Paste the following and edit to suit your needs.

$smtp->datasend("AUTH LOGIN\n")|| die $mess.$smtp->message;
$smtp->response()|| die $mess.$smtp->message;
my $emaillogin = ($TWiki::cfg{SMTP}{Username});
$smtp->datasend(encode_base64($emaillogin))|| die $mess.$smtp->message.$emaillogin;
$smtp->response() || die $mess.$smtp->message;
my $passwd = ($TWiki::cfg{SMTP}{Password});
$smtp->datasend(encode_base64($passwd))|| die $mess.$smtp->message.$passwd;
# $smtp->response()|| die $mess.$smtp->message;
}
$smtp->response();
#set email from @to has two elements, the first being the fully qualified email address
$smtp->mail('THE SAME NAME YOU ARE USING TO LOGIN@Yourdomain.com'); # Don't \@ anywhere, it doesn't work as expected.
my $toemail = @to[0];
$smtp->to($toemail) || die $mess.$smtp->message;
$smtp->data();
$smtp->datasend("From: Use<YOURLOGIN"."@"."Yourdomain.com>\n"); #the @ symbol gets treated wrong if I try to do it another way
$smtp->datasend("To: ".$toemail."\n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: Wiki from your domain");
$smtp->datasend("\n");
$smtp->datasend( $text ) || die $mess.$smtp->message;
$smtp->datasend("\n");

-- AsphaltJesus - 16 Jan 2008

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2008-01-16 - AsphaltJesus
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.