Last Comment Bug 304005 - Add SMTP auth support
: Add SMTP auth support
Status: RESOLVED FIXED
:
Product: Bugzilla
Classification: Server Software
Component: Email Notifications (show other bugs)
: 2.21
: All All
: P1 enhancement with 3 votes (vote)
: Bugzilla 3.2
Assigned To: Frédéric Buclin
: default-qa
:
Mentors:
: 333750 427753 (view as bug list)
Depends on: 309875
Blocks: 459163 469068
  Show dependency treegraph
 
Reported: 2005-08-09 02:44 PDT by Joel Peshkin
Modified: 2008-12-10 20:56 PST (History)
9 users (show)
LpSolit: approval+
mkanat: blocking3.2-
See Also:
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
patch, v1 (4.18 KB, patch)
2008-03-10 09:21 PDT, Frédéric Buclin
wurblzap: review+
Details | Diff | Splinter Review
patch, v2 (5.73 KB, patch)
2008-03-11 16:45 PDT, Frédéric Buclin
mkanat: review+
Details | Diff | Splinter Review

Description Joel Peshkin 2005-08-09 02:44:30 PDT
An irc user inquired about use of SMPT authentication.

According to http://search.cpan.org/~markov/MailTools-1.67/Mail/Mailer.pm it
should be possible to add the additional parameter 
 Auth = [ $user, $password ]
to the Mail::Mailer in order to work with mailservers that require authentication.

To avoid parameter clutter, we could allow the smtpserver parameter to be
specified as either "servername" or "server userid password"

In the validation section of the parameter, we should ensure that Authen::SASL
is installed and complain if it is not.
Comment 1 Roy Pittman 2005-11-14 13:07:01 PST
I have a SMTP send error problem and saw this post. Is this a possible cause to my inability to send from my smtp based account? 
(Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.6) Gecko/20050319 on XPSP2...)

(In reply to comment #0)
> An irc user inquired about use of SMPT authentication.
> 
> According to http://search.cpan.org/~markov/MailTools-1.67/Mail/Mailer.pm it
> should be possible to add the additional parameter 
>  Auth = [ $user, $password ]
> to the Mail::Mailer in order to work with mailservers that require authentication.
> 
> To avoid parameter clutter, we could allow the smtpserver parameter to be
> specified as either "servername" or "server userid password"
> 
> In the validation section of the parameter, we should ensure that Authen::SASL
> is installed and complain if it is not.

Comment 2 Frédéric Buclin 2005-11-17 07:24:48 PST
The trunk is now frozen to prepare Bugzilla 2.22. Enhancement bugs are retargetted to 2.24.
Comment 3 Frédéric Buclin 2006-04-12 11:18:23 PDT
*** Bug 333750 has been marked as a duplicate of this bug. ***
Comment 4 GavinS 2006-08-03 04:06:15 PDT
(I'm just storing a mailing list response from: Thorsten Schöning)


<--

Hello,

i had the same problem with earlier versions of Bugzilla and used a
workaround I found somewhere in a documentation with Net::SMTP. You
should look in your BugMail.pm for the following code and change it.

My problem with SMTP in Versions 2.20 was that I didn't understand
where to save username, password etc. for bugzillas biultin
SMTP-option so I used what worked in earlier version until I have
enough time to fix the problem property with an own mail server oder
something like that.

Maybe it helps.


    MessageToMTA($msg, $user->email);
    #MessageToMTA($msg);

    return 1;
}

#sub MessageToMTA ($) {
#    my ($msg) = (@_);
sub MessageToMTA ($;$) {
   my ($msg, $rcpt_to) = (@_);
    return if (Param('mail_delivery_method') eq "none");

    # Thorsten:
    # Da wir derzeit nur SMTP nutzen und ich mit der Übergabe der
    # Authentifizierungsparameter an Mail::Mailer nicht klarkomme,
    # rufe ich wie vorher Net::SMTP direkt auf.
    use Net::SMTP;
    my $smtp_server = 'mail.domain.de';  # change this
    # Use die on error, so that the mail will be in the 'unsent mails' and
    # can be sent from the sanity check page.
    my $smtp = Net::SMTP->new($smtp_server) ||
    die 'Cannot connect to server \'$smtp_server\'';
    $smtp->mail('bugzilla@domain.de');  # change this
    $smtp->to($rcpt_to);
    $smtp->auth('username', 'password');
    $smtp->data();
    $smtp->datasend($msg);
    $smtp->dataend();
    $smtp->quit;
    return;

    if (Param("mail_delivery_method") eq "sendmail" && $^O =~ /MSWin32/i) {
        open(SENDMAIL, '|' . SENDMAIL_EXE . ' -t -i') ||
            die "Failed to execute " . SENDMAIL_EXE . ": $!\n";
        print SENDMAIL $msg;
        close SENDMAIL;
        return;
    }

-->
Comment 5 Erik Hemdal 2006-08-10 08:12:37 PDT
I crafted a fix for this, because this is not an enhancement for me.  I must have SMTP AUTH, because I now use a hosted email provider that demands it.  I made the fixes in Bugzilla 2.20.1 because that's what we're running.  Here's what we need:

Change defparams.pl to add new paramters smtpauthuser and smtpauthpasswd which are the ISP's user account name and password required for authorization.  
You can put everything into one parameter as was mentioned, but I don't mind having a longer list, and I didn't want to have to do fancy parsing if the user has spaces or other funky stuff in a username or password.

Here's the diff of defparams.pl:

726a727,743
> # local modifications
>   {
>    name => 'smtpauthuser',
>    desc => 'User account name for SMTP auth, if your SMTP server needs it.' . 
>            'Leave blank if you don\'t need to authenticate',
>    type => 't',
>    default => ''
>   },
> 
>   {
>    name => 'smtpauthpasswd',
>    desc => 'Password for the smtpauthuser',
>    type => 't',
>    default => ''
>   },
> # end local modifications
> 

The above will add two params just after 'smtpserver'.

Next, BugMail.pm needs to check for a defined value of smtpauthuser, and if set, push the SMTP AUTH params onto the list of server parameters in @args.  Here's a diff of BugMail.pm:

656,661d655
< 	# Include authorization if credentials are defined
<         if (Param("smtpauthuser") ne '') {
< 	    my $smtpuser = Param("smtpauthuser");
< 	    my $smtpauthpasswd = Param("smtpauthpasswd");
<             push @args, Auth => [ $smtpuser, $smtpauthpasswd ];
< 	}

I did not complete the next part, which is to change checksetup.pl to test for the presence of two packages that Mail::Mailer requires.  They are MIME::Base64 and Authen::SASL.  Authen::SASL will have to be built using whatever underlying authentication your server needs, such as DIGEST-MD5.  But if you use CPAN, you can have CPAN follow the dependencies to build what you need.  I may try to figure out checksetup.pl and if I figure it out, I'll post changes.

I am using this after hacking my local installation.  If the password contains Perl special characters like '@', I think they will need to be escaped in order to pass through.  But the result of these changes produces two new parameters in the list produced by editparams.cgi, and it lets SMTP AUTH work.

I hope this helps. I tried to apply Thorstein's good work, but I found that MessageToMTA() was different in v 2.20.1.  I can't use Bugzilla without authentication, so I had to do something right away.  I hope that this is useful and can find its way into the real release.  

Comment 6 Frédéric Buclin 2006-10-19 12:12:29 PDT
This bug is retargetted to Bugzilla 3.2 for one of the following reasons:

- it has no assignee (except the default one)
- we don't expect someone to fix it in the next two weeks (i.e. before we freeze the trunk to prepare Bugzilla 3.0 RC1)
- it's not a blocker

If you are working on this bug and you think you will be able to submit a patch in the next two weeks, retarget this bug to 3.0.

If this bug is something you would like to see implemented in 3.0 but you are not a developer or you don't think you will be able to fix this bug yourself in the next two weeks, please *do not* retarget this bug.

If you think this bug should absolutely be fixed before we release 3.0, either ask on IRC or use the "blocking3.0 flag".
Comment 7 Erik Hemdal 2006-10-19 13:29:29 PDT
I'm in a quandary.  I would very much like to see this in Bugzilla 3.0; not having this feature is a blocker for me, as I must use SMTP AUTH to use Bugzilla.  At the moment, I am avoiding upgrading because I have to maintain this patch to keep Bugzilla working.

I managed a patch to v2.20 (previously attached) that works for our installation and attached diffs for the affected Perl files.  But I have two blocks:

1.  I'm not a Bugzilla developer and have not been introduced to the dev team.
2.  I don't know how to properly "present" a patch.
3.  I don't have time to craft the updates to checksetup.pl that would be important for making this a real fix -- such as checking for the necessary mailer Perl modules.

Is there any alternative that would get this into production code?  Erik

Erik
Comment 8 bigstijn 2006-12-12 13:39:14 PST
As a quick starting point for Erik:
(In reply to comment #7)

> 1.  I'm not a Bugzilla developer and have not been introduced to the dev team.
check http://www.bugzilla.org/developers/ , I think you can find already a lot of information.

> 2.  I don't know how to properly "present" a patch.
check http://www.bugzilla.org/docs/contributor.html ?  You will probably have to make the change using the 3.0 or tip version.

> 3.  I don't have time to craft the updates to checksetup.pl that would be
> important for making this a real fix -- such as checking for the necessary
> mailer Perl modules.
I would suggest to fill afterwards another bug for the checksetup.pl update.

> Is there any alternative that would get this into production code?
Probably not.

Good luck for 3.2 !
Comment 9 Corris 2007-05-07 14:42:03 PDT
hrm, looks like Email::Send as of at least 2.185 supports smtp auth ( by using Net::SMTP )

http://search.cpan.org/~rjbs/Email-Send-2.185/lib/Email/Send/SMTP.pm

shouldn't be too hard to add a "smtpauthuser" and "smtpauthpass" to pass down when calling Email::Send::send()
Comment 10 Max Kanat-Alexander 2008-02-05 15:14:11 PST
Bugzilla 3.2 is now frozen. Only enhancements blocking 3.2 or specifically approved for 3.2 may be checked in to the 3.2 branch. If you would like to nominate your enhancement for Bugzilla 3.2, set the "blocking3.2" flag to "?", and either the target milestone will be changed back, or the blocking3.2 flag will be granted, if we will accept this enhancement for Bugzilla 3.2.
Comment 11 Max Kanat-Alexander 2008-02-06 00:26:18 PST
This doesn't even have a patch or an assignee, so it isn't something we can take on the branch.
Comment 12 Frédéric Buclin 2008-03-10 09:21:19 PDT
Created attachment 308415 [details] [diff] [review]
patch, v1

There has been so many requests to support SMTP auth that I decided to fix it myself. Looking at the doc about Net::SMTP and Email::Send::SMTP, it seems as simple as that. I have no way to test my patch, so I will let the reviewer do it for me.
Comment 13 Marc Schumann [:Wurblzap] 2008-03-10 12:46:00 PDT
Comment on attachment 308415 [details] [diff] [review]
patch, v1

r=Wurblzap by inspection. Code is ok, testing is still needed.
Comment 14 Max Kanat-Alexander 2008-03-11 16:17:22 PDT
Comment on attachment 308415 [details] [diff] [review]
patch, v1

>Index: Bugzilla/Mailer.pm
>+                    username => Bugzilla->params->{"smtp_username"},
>+                    password => Bugzilla->params->{"smtp_password"},

  I'm a bit concerned what would happen here with SMTP servers that don't support authentication. I think these parameters should only be passed if they are not empty.

>+  {
>+   name => 'smtp_password',
>+   type => 't',
>+   default => ''
>+  },

  I'd really like to make that a password box, if possible.

>Index: template/en/default/admin/params/mta.html.tmpl
>+  smtp_username => "The username to pass to the SMTP server for SASL authentication. " _
>+                   "Leave this field empty if your SMTP server doesn't require authentication.",

  Don't use the term "SASL authentication" as most administrators won't know what that is. You can just say "SMTP authentication" instead.
Comment 15 Frédéric Buclin 2008-03-11 16:45:56 PDT
Created attachment 308756 [details] [diff] [review]
patch, v2

Fixing mkanat's comments. About the username and password, $smtp->auth() is only called if the username is not empty, so that's fine.
Comment 16 Max Kanat-Alexander 2008-03-11 16:47:55 PDT
Comment on attachment 308756 [details] [diff] [review]
patch, v2

This looks fine to me.
Comment 17 Frédéric Buclin 2008-03-13 16:56:54 PDT
OK, I tested my patch with smtp.aim.com (I forgot I had access to it) and it's working fine:

Net::SMTP=GLOB(0x9ee9fdc)<<< 235 AUTHENTICATION SUCCESSFUL
...
Net::SMTP=GLOB(0x9ee9fdc)<<< 250 OK

And I correctly got the bugmail in my mailbox.


With the smtp_username and smtp_password fields left empty, or without my patch applied, I get in both cases:

Net::SMTP=GLOB(0x9acf47c)<<< 556 CLIENT AUTHENTICATION REQUIRED. USE ESMTP EHLO AND AUTH.
Net::SMTP=GLOB(0x9acf47c)<<< 503 BAD SEQUENCE OF COMMANDS


So it seems to work fine. Approving for 3.2, per discussion with mkanat on IRC.
Comment 18 Frédéric Buclin 2008-03-13 17:06:28 PDT
Just on time for Bugzilla 3.1.4. :)

Checking in Bugzilla/Mailer.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Mailer.pm,v  <--  Mailer.pm
new revision: 1.18; previous revision: 1.17
done
Checking in Bugzilla/Config/Common.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Config/Common.pm,v  <--  Common.pm
new revision: 1.20; previous revision: 1.19
done
Checking in Bugzilla/Config/MTA.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Config/MTA.pm,v  <--  MTA.pm
new revision: 1.16; previous revision: 1.15
done
Checking in Bugzilla/Install/Requirements.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Install/Requirements.pm,v  <--  Requirements.pm
new revision: 1.43; previous revision: 1.42
done
Checking in template/en/default/admin/params/common.html.tmpl;
/cvsroot/mozilla/webtools/bugzilla/template/en/default/admin/params/common.html.tmpl,v  <--  common.html.tmpl
new revision: 1.6; previous revision: 1.5
done
Checking in template/en/default/admin/params/mta.html.tmpl;
/cvsroot/mozilla/webtools/bugzilla/template/en/default/admin/params/mta.html.tmpl,v  <--  mta.html.tmpl
new revision: 1.12; previous revision: 1.11
done
Comment 19 Frédéric Buclin 2008-04-08 07:18:10 PDT
*** Bug 427753 has been marked as a duplicate of this bug. ***
Comment 20 Max Kanat-Alexander 2008-07-01 00:07:25 PDT
Added to the release notes for Bugzilla 3.2 in a patch on bug 432331.
Comment 21 Daniel Mack 2008-08-12 00:56:02 PDT
Bugzilla 3.04 stops working after applying this patch! Here is da Log:

Can't locate Bugzilla/Install/Requirements.pm in @INC (@INC contains: . /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl) at Bugzilla/Version.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Version.pm line 24.
Compilation failed in require at Bugzilla/Product.pm line 21.
BEGIN failed--compilation aborted at Bugzilla/Product.pm line 21.
Compilation failed in require at Bugzilla/User.pm line 48.
BEGIN failed--compilation aborted at Bugzilla/User.pm line 48.
Compilation failed in require at Bugzilla/Auth/Verify.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify.pm line 24.
Compilation failed in require at (eval 14) line 3.
        ...propagated at /usr/share/perl/5.8/base.pm line 84.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify/Stack.pm line 19.
Compilation failed in require at Bugzilla/Auth.pm line 36.
BEGIN failed--compilation aborted at Bugzilla/Auth.pm line 36.
Compilation failed in require at Bugzilla.pm line 31.
BEGIN failed--compilation aborted at Bugzilla.pm line 31.
Compilation failed in require at /var/www/editparams.cgi line 28.
BEGIN failed--compilation aborted at /var/www/editparams.cgi line 28.
Can't locate Bugzilla/Install/Requirements.pm in @INC (@INC contains: . /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl) at Bugzilla/Version.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Version.pm line 24.
Compilation failed in require at Bugzilla/Product.pm line 21.
BEGIN failed--compilation aborted at Bugzilla/Product.pm line 21.
Compilation failed in require at Bugzilla/User.pm line 48.
BEGIN failed--compilation aborted at Bugzilla/User.pm line 48.
Compilation failed in require at Bugzilla/Auth/Verify.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify.pm line 24.
Compilation failed in require at (eval 14) line 3.
        ...propagated at /usr/share/perl/5.8/base.pm line 84.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify/Stack.pm line 19.
Compilation failed in require at Bugzilla/Auth.pm line 36.
BEGIN failed--compilation aborted at Bugzilla/Auth.pm line 36.
Compilation failed in require at Bugzilla.pm line 31.
BEGIN failed--compilation aborted at Bugzilla.pm line 31.
Compilation failed in require at /var/www/editparams.cgi line 28.
BEGIN failed--compilation aborted at /var/www/editparams.cgi line 28.
Can't locate Bugzilla/Install/Requirements.pm in @INC (@INC contains: . /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl) at Bugzilla/Version.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Version.pm line 24.
Compilation failed in require at Bugzilla/Product.pm line 21.
BEGIN failed--compilation aborted at Bugzilla/Product.pm line 21.
Compilation failed in require at Bugzilla/User.pm line 48.
BEGIN failed--compilation aborted at Bugzilla/User.pm line 48.
Compilation failed in require at Bugzilla/Auth/Verify.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify.pm line 24.
Compilation failed in require at (eval 14) line 3.
        ...propagated at /usr/share/perl/5.8/base.pm line 84.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify/Stack.pm line 19.
Compilation failed in require at Bugzilla/Auth.pm line 36.
BEGIN failed--compilation aborted at Bugzilla/Auth.pm line 36.
Compilation failed in require at Bugzilla.pm line 31.
BEGIN failed--compilation aborted at Bugzilla.pm line 31.
Compilation failed in require at /var/www/index.cgi line 34.
BEGIN failed--compilation aborted at /var/www/index.cgi line 34.
Can't locate Bugzilla/Install/Requirements.pm in @INC (@INC contains: . /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl) at Bugzilla/Version.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Version.pm line 24.
Compilation failed in require at Bugzilla/Product.pm line 21.
BEGIN failed--compilation aborted at Bugzilla/Product.pm line 21.
Compilation failed in require at Bugzilla/User.pm line 48.
BEGIN failed--compilation aborted at Bugzilla/User.pm line 48.
Compilation failed in require at Bugzilla/Auth/Verify.pm line 24.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify.pm line 24.
Compilation failed in require at (eval 14) line 3.
        ...propagated at /usr/share/perl/5.8/base.pm line 84.
BEGIN failed--compilation aborted at Bugzilla/Auth/Verify/Stack.pm line 19.
Compilation failed in require at Bugzilla/Auth.pm line 36.
BEGIN failed--compilation aborted at Bugzilla/Auth.pm line 36.
Compilation failed in require at Bugzilla.pm line 31.
BEGIN failed--compilation aborted at Bugzilla.pm line 31.
Compilation failed in require at /var/www/index.cgi line 34.
BEGIN failed--compilation aborted at /var/www/index.cgi line 34.
Comment 22 Frédéric Buclin 2008-08-12 05:46:34 PDT
(In reply to comment #21)
> Bugzilla 3.04 stops working after applying this patch! Here is da Log:

Unrelated to this patch. You didn't run checksetup.pl after applying the patch, that's why.
Comment 23 Daniel Mack 2008-08-12 06:49:33 PDT
(In reply to comment #22)
> (In reply to comment #21)
> > Bugzilla 3.04 stops working after applying this patch! Here is da Log:
> 
> Unrelated to this patch. You didn't run checksetup.pl after applying the patch,
> that's why.
> 
wrong, checksetup.pl fails woth several errors after the patch ... this hack pretty **** up my bugzilla, i had to reinstall everything . it worked perfectly before that
Comment 24 Daniel Mack 2008-08-12 06:52:44 PDT
additionally, even patch -p0 fails ... well what a erroneous piece of software-****, huh. Well i solved my SMTP-AUTH-problem pretty easy: use Exim as Smarthost-Relay :-). Bye
Comment 25 Frédéric Buclin 2008-08-12 06:57:16 PDT
(In reply to comment #23)
> wrong, checksetup.pl fails woth several errors after the patch ... this hack
> pretty fucked up my bugzilla

(In reply to comment #24)
> additionally, even patch -p0 fails ... well what a erroneous piece of
> software-shit

OK, before complaining that the patch is buggy, start reading the target milestone of this bug, and you will notice that it indicates "Bugzilla 3.2", meaning that the patch doesn't apply to 3.0.4. Now if it messed up your installation, that's not our fault, but yours. Bye.

Note You need to log in before you can comment on or make changes to this bug.