EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #05859


< 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 3


Good Afternoon,
I modified the Email.pm file to send mail through an account in gmail .

The modified code 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 = "">
    # 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;
}

 

 

 

But when sending mail, displays the following error:
Can't locate object method "new" via package "Net::SMTP::TLS" (perhaps you forgot to load "Net::SMTP::TLS"?) at /usr/share/eprints3/perl_lib/EPrints/Email.pm line 163.
 
How do I correct this error ?
 
How do I get to send mail through an account in gmail ?
 
 
Thank you