Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created May 6, 2009 08:10
Show Gist options
  • Save miyagawa/107431 to your computer and use it in GitHub Desktop.
Save miyagawa/107431 to your computer and use it in GitHub Desktop.
Support SMTP TLS (for Gmail)
diff --git a/plugins/queue/smtp-forward b/plugins/queue/smtp-forward
index f7e212b..00f42a1 100644
--- a/plugins/queue/smtp-forward
+++ b/plugins/queue/smtp-forward
@@ -35,7 +35,11 @@ sub init {
if (@args > 1 and $args[1] =~ /^(\d+)$/) {
$self->{_smtp_port} = $1;
}
- $self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 2);
+ if (@args > 2 and $args[2] && $args[3]) {
+ $self->{_smtp_user} = $args[2];
+ $self->{_smtp_pass} = $args[3];
+ }
+# $self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 2);
} else {
die("No SMTP server specified in smtp-forward config");
}
@@ -46,7 +50,9 @@ sub hook_queue {
my ($self, $transaction) = @_;
$self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}");
- my $smtp = Net::SMTP->new(
+ my $class = $self->{_smtp_port} == 465 ? "Net::SMTP::TLS" : "Net::SMTP";
+ eval "require $class" or die $@;
+ my $smtp = $class->new(
$self->{_smtp_server},
Port => $self->{_smtp_port},
Timeout => 60,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment