EPrints Technical Mailing List Archive

Message: #06894


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Using Gmail SMTP for sending emails with Eprints 3


Good afternoon, I configured the Email.pm file to be able to send emails
using a gmail account.
The configuration is as follows:
sub send_mail_via_smtp
{
    my( %p ) = @_;

    eval 'use Net::SMTP::TLS';

    my $repository = $p{session}->get_repository;

    my $smtphost = $repository->get_conf( 'smtp_server' );
    ##my $smtphost = 'smtp.gmail.com';

    if( !defined $smtphost )
    {
        $repository->log( "No STMP host has been defined. To fix this, find
the full\naddress of your SMTP server (eg. smtp.example.com) and add it\nas
the value of smtp_server in\nperl_lib/EPrints/SystemSettings.pm" );
        return( 0 );
    }


    my $smtp = new Net::SMTP::TLS (
           $smtphost,
        Hello   =>      'eprints-server.on-linux.org',
        Port    =>      587,
        User    =>      'eprints-server@gmail.com',
        Password=>      'gmail_password',
        );

    # my $smtp = Net::SMTP->new( $smtphost);

    if( !defined $smtp )
    {
        $repository->log( "Failed to create smtp connection to $smtphost" );
        return( 0 );
    }

    $smtp->mail( $p{from_email} );
    $smtp->to( $p{to_email} );
    
    # if( !$smtp->recipient( $p{to_email} ) )    
    # {
    #    $repository->log( "smtp server refused <$p{to_email}>" );
    #    $smtp->quit;
    #    return 0;
    # }

    my $message = build_email( %p );
    my $data = $message->as_string;
    # Send the message as bytes, to avoid Net::Cmd wide-character warnings
    utf8::encode($data);
    $smtp->data;
    $smtp->datasend( $data );
    $smtp->dataend;
    $smtp->quit;

    return 1;



I also edited the following line in
$Eprints3PATH/perl_lib/EPrint/SystemSettings.pm
 ....
 'smtp_server' => 'smtp.gmail.com',
 ....


Am getting this error from the browser when attempting to send test mail: 
Can't locate object method "new" via package "Net::SMTP::TLS" (perhaps you
forgot to load "Net::SMTP::TLS"?) at
/usr/share/eprints/perl_lib/EPrints/Email.pm line 170.
Why is this? 
How do I send emails using a gmail account?

Thanks.
Ernesto