qpsmtpd Wiki


You are here: start » plugins » auth » auth_smtpd


You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.


You don't have an account yet? Just get one: Register

Forgotten your password? Get a new one: Set new password

#!/usr/bin/perl -Tw
=head1 NAME
auth_smtpd - Authenticate user via local network SMTP server
This plugin implements a authentication plugin that check sender is the
user of SMTP server in local network.
Add the plugin to the plugins file in the configuration directory:
auth/auth_smtpd smtp_server smtp_port
Replace smtp_server and smtp_port with the IP address and port number of the SMTP server that will provide the authentication.
Defaults to an IP address of and port 25.
=head1 NOTES
Requires the Net::SMTP::TLS CPAN module.
=head1 AUTHOR
Original plugin by: jennifer@thecomputerclinic.ca
Plugin updated by:  James Turnbull (james@lovedthanlost.net)
sub register {
  my ( $self, $qp, @args ) = @_;
  $self->register_hook( "auth-plain", "auth_smtpd" );
  $self->register_hook( "auth-login", "auth_smtpd" );
  $self->register_hook( "auth-cram-md5", "auth_smtpd" );
  if (@args > 0) {
    if ($args[0] =~ /^([\.\w_-]+)$/) {
      $self->{_smtp_server} = $1;
    else {
      die "Bad data in smtp server: $args[0]";
    $self->{_smtp_port} = 25;
    if (@args > 1 and $args[1] =~ /^(\d+)$/) {
      $self->{_smtp_port} = $1;
    $self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if
(@args > 2);
  } else {
    die("No SMTP server specified in plugins file.");
 # set any values that are not already
  $self->{_smtp_server} ||= "";
  $self->{_smtp_port} ||= 25;
sub auth_smtpd {
  use Net::SMTP::TLS;
  my ( $self, $transaction, $mechanism, $user, $clearPassword, $hashPassword, $ticket
) =
  my ($smtpdhost, $smtpdport, $mesg);
  # pull values in from config
  $smtpdhost = $self->{_smtp_server};
  $smtpdport = $self->{_smtp_port};
 my $mailer;
 $self->log(LOGINFO, "auth_smtpd/Used $mechanism authentication mechanism for $user on server $smtpdhost at port $smtpdport.");
 eval {
 $mailer = new Net::SMTP::TLS(
        Hello   =>      '',
        Port    =>      $smtpdport,
        User    =>      $user,
        Password=>      $clearPassword) ;
 # failed
 if ($@){
    return DECLINED;
    return ( DENY, "auth_smtpd/$mechanism authentication for $user failed."
 } else {
   return ( OK, "auth_smtpd/$mechanism authentication for $user" );