PDA

Ver la Versión Completa : Enviar email gmail


elguille
18-05-2016, 17:17:25
Hasta ayer enviaba correos mediante gmail con el codigo de mas abajo, pero de golpe y porrazo ha dejado de funcionar con todas las cuentas de gmail a las que tengo acceso, investigando en la web sospecho que gmail ya ha dejado de soportar SSLv3 http://googleappsupdates.blogspot.com.es/2016/05/disabling-support-for-sslv3-and-rc4-for.html
¿alguien sabe algo mas del tema? ¿alguien sabe como enviar por gmail mediante otro codigo?

uses IdHTTP, WinInet, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack,
IdSSL, IdSSLOpenSSL, IdExplicitTLSClientServerBase, Datasnap.DBClient,
IdBaseComponent, IdComponent, IdTCPServer, IdSMTPServer, tzprimds, ucommon, utzcds, utzfds,
IdMessage, IdEMailAddress, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, idexception, myaccess, IdAttachmentFile,
IdRawBase, IdRawClient, IdIcmpClient, IdSSLOpenSSLHeaders;

procedure emailgmail(host: string; nombre: string; password: string; port: integer; desde: string; hasta: string; asunto: string; cuerpo: string; adjunto: string);
var
IDSMTP1: TIDSMTP; // Componente de envio de correo
IdSSLIOHandlerSocketOpenSSL: tIdSSLIOHandlerSocketOpenSSL;
Mensaje: TIdMessage;
begin
screen.cursor := crhourglass;
IdSSLIOHandlerSocketOpenSSL := tIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocketOpenSSL.Destination := host + ':' + IntToStr(port); // 'smtp.gmail.com:465';
IdSSLIOHandlerSocketOpenSSL.host := host + ':' + IntToStr(port);;
IdSSLIOHandlerSocketOpenSSL.port := port;
IdSSLIOHandlerSocketOpenSSL.ssloptions.method := sslvSSLv3;
IdSSLIOHandlerSocketOpenSSL.ssloptions.mode := sslmUnassigned;
IDSMTP1 := TIDSMTP.Create(nil);
IDSMTP1.UserNAME := nombre;
IDSMTP1.password := password;
IDSMTP1.host := host;
IDSMTP1.port := port;
IDSMTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL;
IDSMTP1.UseTLS := utUseImplicitTLS;

Mensaje := TIdMessage.Create(nil);
with Mensaje do
begin
Body.Add(cuerpo);
From.Text := desde;
Recipients.EMailAddresses := hasta;
Subject := asunto;
Priority := TIdMessagePriority(mpHighest); // prioridad del mensaje
CCList.EMailAddresses := '';
BccList.EMailAddresses := '';
if adjunto <> '' THEN
TIdAttachmentfile.Create(Mensaje.MessageParts, adjunto);
end;
with IDSMTP1 do
begin
try
Connect;
try
// Envio el mensaje.
Send(Mensaje);
log(ExtractFilePath(application.ExeName) + 'emailseviados.log', hasta + '|' + asunto + '|' + cuerpo + '|' + adjunto);
finally
Disconnect;
end;
// MessageDlg('Enviado Correctamente', mtInformation, [mbOK], 0);
except
// Capturo algunas excepciones que pueden ocurrir
{ ON E: EProtocolReplyError do begin
MessageDlg('No se ha podido enviar el email.' + #13 +
'Incorrecto el email o el usuario o la password.', mtError, [mbOK], 0);
end; }
on e: EFOpenError do
begin
MessageDlg('No se ha podido enviar el email.' + #13 + 'Fichero Adjunto desconocido o erróneo.', mtError, [mbOK], 0);
end;
{ on E: EIdSocketError do begin
MessageDlg('No se ha podido enviar el email.'+ #13 +
'Host desconocido o incorrecto.', mtError, [mbOK], 0);
end }
else
begin
MessageDlg('Fallo en el envio de email', mtError, [mbOK], 0);
end;
end;
end;
screen.cursor := crdefault;
ENd;

elguille
18-05-2016, 17:27:23
Ya he activado el "acceso de aplicaciones menos seguras" , ese no es el problema.

elguille
19-05-2016, 12:12:54
Solucionado de momento
http://clubdelphi.com/foros/showthread.php?p=505329&posted=1#post505329