Gmail::SendMail - Enviando emails usando gmail
Publicado por Daniel Vinciguerra (última atualização em 23/09/2011)
[ Hits: 9.640 ]
Homepage: http://bivee.com.br
Download 1316628004.send-mail.pl (versão 2)
Esta é uma implementação simples de uma classe para trabalhar com envios de emails utilizando como base o servidor do gmail.com.
Melhore, brinque, altere, estude ou use este exemplo como preferir, contanto que mantenha a referencia e use-o para aumentar seus conhecimentos. ;)
Observação:
Depende do módulo Net::SMTP::TLS ( $ sudo perl -MCPAN -e "install Net::SMTP::TLS" )
Versão 2 - Enviado por Daniel Vinciguerra em 21/09/2011
Changelog: Esta é uma implementação simples de uma classe para trabalhar com envios de emails utilizando como base o servidor do gmail.com.
Melhore, brinque, altere, estude ou use este exemplo como preferir, contanto que mantenha a referencia e use-o para aumentar seus conhecimentos. ;)
Observação:
Depende do módulo Net::SMTP::TLS e do Class::Accessor
( $ sudo perl -MCPAN -e "install Net::SMTP::TLS" )
( $ sudo perl -MCPAN -e "install Class::Accessor" )
Download 1316628004.send-mail.pl
#!/usr/bin/perl # (c) 2011 Bivee. All rights reserveds. # author dvicniguerra < dan.vinciguerra at gmail.com > # # This script is distributed under Perl Itself License # package Gmail::SendMail; use strict; use warnings; # default constructor sub new { return bless { server => 'smtp.gmail.com', port => 587, }, shift || ref shift; } sub configure { my ( $self, %param ) = ( shift, @_ ); eval { $self->{username} = $param{username} || ""; $self->{password} = $param{password} || ""; }; if ( $@ ) { die "Error setting authentication credentials: $@ "; } } # accessor to server attribute sub server { $_[0]->{server} = $_[1] if defined $_[1]; return shift->{server}; } # accessor to port attribute sub port { $_[0]->{port} = $_[1] if defined $_[1]; return shift->{port}; } # accessor to username attribute sub username { $_[0]->{username} = $_[1] if defined $_[1]; return shift->{username}; } # accessor to password attribute sub password { $_[0]->{password} = $_[1] if defined $_[1]; return shift->{password}; } # accessor to from attribute sub from { $_[0]->{from} = $_[1] if defined $_[1]; return shift->{from}; } # accessor to "to" attribute sub to { $_[0]->{to} = $_[1] if defined $_[1]; return shift->{to}; } # accessor to body attribute sub body { $_[0]->{body} = $_[1] if defined $_[1]; return shift->{body}; } # send message method sub send { my $self = shift; eval { use Net::SMTP::TLS; # config mailer my $mail = Net::SMTP::TLS->new( $self->server, Hello => $self->server, Port => $self->port, User => $self->username, Password=> $self->password, ); # config mail $mail->mail( $self->from ); $mail->to( $self->to ); $mail->data; $mail->datasend( $self->body ); $mail->dataend; $mail->quit; }; if ( $@ ) { die "Error sending mail: $@ "; } } package main; # getting new object instance my $app = Gmail::SendMail->new; # setting user authentication $app->configure( username => 'dan.vinciguerra@gmail.com', password => 'Alexia**', ); # setting message informations $app->from( 'dan.vicniguerra@gmail.com' ); $app->to( 'dan.vinciguerra@gmail.com' ); $app->body( qq{ Hi pretty, Do you want to go to party with me today? :) see ya, Daniel Vinciguerra This message was sent using Perl. ;) } ); # lets rock baby ;) $app->send; __END__ =head1 NAME Gmail::SendMail - Exemplo Gmail sender =head1 DESCRIPTION Esta é uma implementação simples de uma classe para trabalhar com envios de emails utilizando como base o servidor do gmail.com. =head1 SINOPSYS use Gmail::SendMail; my $app = Gmail::SendMail->new; $app->configure( username => 'usuario_gmail', password => 'senha_gmail', ); $app->from( 'foo@gmail.com' ); $app->to( 'bar@gmail.com' ); $app->body( 'Minha bicicleta amarela!' ); $app->send; =head1 SEE ALSO L<Net::SMTP::TLS>, L<perl> =head1 AUTHOR Daniel Vinciguerra < dan.vinciguerra at gmail.com > =cut
Buscar Traduções no Google Translate
Perl Check Port - Entenda melhor os sockets
Nenhum comentário foi encontrado.
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
O Que Fazer Após Instalar Fedora 42
Debian 12 -- Errata - Correções de segurança
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Meu PC perde o boot de várias distros Linux após ficar desligado (4)
Véi, é sem condição de uso (1)