Enviar e-mail utilizando componente Indy (smtp.live.com)
Olá pessoal !
Estou com o seguinte problema : estou tentando implementar no meu sistema, para enviar e-mail utilizando smtp do hotmail, pelo o que já pesquisei parece que a Microssoft implementou alguns métodos novos de segurança como SSl , devido a isso não estou conseguindo enviar os e-mail's. Nos teste que eu fiz utilizei as portas : 25 / 110 / 587. Estou colocando em anexo um programa que fiz para teste, para os colegas me ajudarem se tiverem solução para o problema.
Segue o meu e-mail para solicitar o email com os fontes do programa : eliel_martins@hotmail.com
Segue o código fonte se ajudar :
unit uPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdText, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, IdMessage,
IdAttachmentFile, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL,
IdSSLOpenSSL, Buttons, StdCtrls;
type
TForm1 = class(TForm)
EdtDominio: TEdit;
EdtPorta: TEdit;
EdtUsuario: TEdit;
EdtSenha: TEdit;
EdtEmail_Remetente: TEdit;
EdtRemetente: TEdit;
BtnEnviar: TSpeedButton;
SpeedButton1: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
EdtDestinatario: TEdit;
EdtEmailDestinatario: TEdit;
EdtAssunto: TEdit;
MmCorpo: TMemo;
Label10: TLabel;
procedure SpeedButton1Click(Sender: TObject);
procedure BtnEnviarClick(Sender: TObject);
private
{ Private declarations }
function EnviarEmail(Dominio,
Porta,
Usuario,
Senha,
DeNome,
DeEmail,
Para,
Assunto,
Corpo : string;
CorpoMIME,
AnexoMIME : integer;
AutoResposta : Boolean) : Boolean;
function EmailTipoMIME( TipoMIME : Integer ) : String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.BtnEnviarClick(Sender: TObject);
begin
if EnviarEmail(EdtDominio.Text,
EdtPorta.Text,
EdtUsuario.Text,
EdtSenha.Text,
EdtRemetente.Text,
EdtEmail_Remetente.Text,
EdtDestinatario.Text,
EdtAssunto.Text,
MmCorpo.Text,
0,
0,
False) then begin
ShowMessage('E-mail enviado com sucesso !');
end;
end;
function TForm1.EmailTipoMIME(TipoMIME: Integer): String;
begin
case TipoMIME of
0 : result := 'text/plain';
1 : result := 'text/html';
2 : result := 'text/richtext';
3 : result := 'text/x-aiff';
4 : result := 'audio/basic';
5 : result := 'audio/wav';
6 : result := 'image/gif';
7 : result := 'image/jpeg';
8 : result := 'image/pjpeg';
9 : result := 'image/tiff';
10 : result := 'image/x-png';
11 : result := 'image/x-xbitmap';
12 : result := 'image/bmp';
13 : result := 'image/x-jg';
14 : result := 'image/x-emf';
15 : result := 'image/x-wmf';
16 : result := 'video/avi';
17 : result := 'video/mpeg';
18 : result := 'application/postscript';
19 : result := 'application/base64';
20 : result := 'application/macbinhex40';
21 : result := 'application/pdf';
22 : result := 'application/x-compressed';
23 : result := 'application/x-zip-compressed';
24 : result := 'application/x-gzip-compressed';
25 : result := 'application/java';
26 : result := 'application/x-msdownload';
27 : result := 'application/octet-stream';
28 : result := 'multipart/mixed';
29 : result := 'multipart/relative';
30 : result := 'multipart/digest';
31 : result := 'multipart/alternative';
32 : result := 'multipart/related';
33 : result := 'multipart/report';
34 : result := 'multipart/signed';
35 : result := 'multipart/encrypted';
end;
end;
function TForm1.EnviarEmail(Dominio, Porta, Usuario, Senha, DeNome, DeEmail,
Para, Assunto, Corpo: string;
CorpoMIME, AnexoMIME: integer;
AutoResposta: Boolean): Boolean;
Var
I : Integer;
IdCorpo : TIdText;
IdSmtp : TIdSMTP;
IdMessage : TIdMessage;
IdAnexo : TIdAttachmentFile;
IdSSl : TIdSSLIOHandlerSocketOpenSSL;
begin
{Função enviar e-mail}
try
IdMessage := TIdMessage.Create(nil);
try
{Cria a Estrutura da Mensagem}
IdMessage.Clear;
IdMessage.IsEncoded := True;
IdMessage.AttachmentEncoding := 'MIME';
IdMessage.Encoding := meMIME;
IdMessage.ConvertPreamble := True;
IdMessage.Priority := mpNormal;
IdMessage.ContentType := 'multipart/mixed';
IdMessage.CharSet := 'ISO-8859-1';
IdMessage.Date := Now;
{Define o Remetente e Destinatário}
IdMessage.From.Address := DeEmail;
IdMessage.From.Text := DeNome + '';
IdMessage.ReplyTo.EMailAddresses := DeEmail;
IdMessage.Recipients.EMailAddresses := Trim(Para);
if AutoResposta then begin
IdMessage.ReceiptRecipient.Text := DeEmail;
end;
IdMessage.Subject := Trim( Assunto );
{Adiciona o CORPO da Mensagem}
IdCorpo := TIdText.Create(IdMessage.MessageParts,nil);
IdCorpo.ContentType := EmailTipoMIME(CorpoMIME);
IdCorpo.ContentDescription := 'multipart-1';
IdCorpo.CharSet := 'ISO-8859-1';
IdCorpo.ContentTransfer := '16bit';
IdCorpo.ContentDescription := 'Corpo da Mensagem';
IdCorpo.Body.Clear;
IdCorpo.Body.Add( Corpo );
IdSMTP := TIdSMTP.Create(nil);
if Porta = '25' then begin
With IdSMTP Do begin
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create( nil );
IdSMTP.IOHandler := IdSSL;
UseTLS := utUseImplicitTLS;
except
on E: Exception do begin
IOHandler := TIdIOHandler.MakeDefaultIOHandler( nil );
UseTLS := utNoTLSSupport;
ShowMessage('SSL da Autenticação Segura Falhou.' + #13 + '' + #13 +
'Pode ser uma instabilidade temporária na ' + #13 +
'conexão de sua Internet.' + #13 + '' +#13+
'Tente de novo agora ou mais tarde.');
result := False;
end;
end;
IdSSL.SSLOptions.Method := sslvSSLv2;
IdSSL.SSLOptions.Mode := sslmClient;
end;
end;
With IdSMTP Do
try
AuthType := SatDefault;
ReadTimeout := 10000;
Host := Dominio;
Port := StrToInt(Porta);
UserName := Usuario;
Password := Senha;
try
Connect;
Authenticate;
except
on E: Exception do begin
ShowMessage('Autenticação Falhou.' +#13+ '' + #13 +
'Verifique seu Nome de Usuário e Senha ou '+#13+
'Tente de novo agora ou mais tarde.');
result := False;
end;
end;
if Connected then begin
Send( IdMessage );
result := True;
end else begin
raise Exception.Create('A conexão com o Provedor foi interrompida.' + #13 + '' + #13 +
'Verifique se a sua Internet está ativa.');
result := False;
end;
finally
Disconnect;
end;
except
result := false;
end;
finally
FreeAndNil( IdMessage );
FreeAndNil( IdSMTP );
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Close;
end;
end.
x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*
Desde já agradeço a atenção de todos.
Eliel G. Martins
Estou com o seguinte problema : estou tentando implementar no meu sistema, para enviar e-mail utilizando smtp do hotmail, pelo o que já pesquisei parece que a Microssoft implementou alguns métodos novos de segurança como SSl , devido a isso não estou conseguindo enviar os e-mail's. Nos teste que eu fiz utilizei as portas : 25 / 110 / 587. Estou colocando em anexo um programa que fiz para teste, para os colegas me ajudarem se tiverem solução para o problema.
Segue o meu e-mail para solicitar o email com os fontes do programa : eliel_martins@hotmail.com
Segue o código fonte se ajudar :
unit uPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdText, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, IdMessage,
IdAttachmentFile, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL,
IdSSLOpenSSL, Buttons, StdCtrls;
type
TForm1 = class(TForm)
EdtDominio: TEdit;
EdtPorta: TEdit;
EdtUsuario: TEdit;
EdtSenha: TEdit;
EdtEmail_Remetente: TEdit;
EdtRemetente: TEdit;
BtnEnviar: TSpeedButton;
SpeedButton1: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
EdtDestinatario: TEdit;
EdtEmailDestinatario: TEdit;
EdtAssunto: TEdit;
MmCorpo: TMemo;
Label10: TLabel;
procedure SpeedButton1Click(Sender: TObject);
procedure BtnEnviarClick(Sender: TObject);
private
{ Private declarations }
function EnviarEmail(Dominio,
Porta,
Usuario,
Senha,
DeNome,
DeEmail,
Para,
Assunto,
Corpo : string;
CorpoMIME,
AnexoMIME : integer;
AutoResposta : Boolean) : Boolean;
function EmailTipoMIME( TipoMIME : Integer ) : String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.BtnEnviarClick(Sender: TObject);
begin
if EnviarEmail(EdtDominio.Text,
EdtPorta.Text,
EdtUsuario.Text,
EdtSenha.Text,
EdtRemetente.Text,
EdtEmail_Remetente.Text,
EdtDestinatario.Text,
EdtAssunto.Text,
MmCorpo.Text,
0,
0,
False) then begin
ShowMessage('E-mail enviado com sucesso !');
end;
end;
function TForm1.EmailTipoMIME(TipoMIME: Integer): String;
begin
case TipoMIME of
0 : result := 'text/plain';
1 : result := 'text/html';
2 : result := 'text/richtext';
3 : result := 'text/x-aiff';
4 : result := 'audio/basic';
5 : result := 'audio/wav';
6 : result := 'image/gif';
7 : result := 'image/jpeg';
8 : result := 'image/pjpeg';
9 : result := 'image/tiff';
10 : result := 'image/x-png';
11 : result := 'image/x-xbitmap';
12 : result := 'image/bmp';
13 : result := 'image/x-jg';
14 : result := 'image/x-emf';
15 : result := 'image/x-wmf';
16 : result := 'video/avi';
17 : result := 'video/mpeg';
18 : result := 'application/postscript';
19 : result := 'application/base64';
20 : result := 'application/macbinhex40';
21 : result := 'application/pdf';
22 : result := 'application/x-compressed';
23 : result := 'application/x-zip-compressed';
24 : result := 'application/x-gzip-compressed';
25 : result := 'application/java';
26 : result := 'application/x-msdownload';
27 : result := 'application/octet-stream';
28 : result := 'multipart/mixed';
29 : result := 'multipart/relative';
30 : result := 'multipart/digest';
31 : result := 'multipart/alternative';
32 : result := 'multipart/related';
33 : result := 'multipart/report';
34 : result := 'multipart/signed';
35 : result := 'multipart/encrypted';
end;
end;
function TForm1.EnviarEmail(Dominio, Porta, Usuario, Senha, DeNome, DeEmail,
Para, Assunto, Corpo: string;
CorpoMIME, AnexoMIME: integer;
AutoResposta: Boolean): Boolean;
Var
I : Integer;
IdCorpo : TIdText;
IdSmtp : TIdSMTP;
IdMessage : TIdMessage;
IdAnexo : TIdAttachmentFile;
IdSSl : TIdSSLIOHandlerSocketOpenSSL;
begin
{Função enviar e-mail}
try
IdMessage := TIdMessage.Create(nil);
try
{Cria a Estrutura da Mensagem}
IdMessage.Clear;
IdMessage.IsEncoded := True;
IdMessage.AttachmentEncoding := 'MIME';
IdMessage.Encoding := meMIME;
IdMessage.ConvertPreamble := True;
IdMessage.Priority := mpNormal;
IdMessage.ContentType := 'multipart/mixed';
IdMessage.CharSet := 'ISO-8859-1';
IdMessage.Date := Now;
{Define o Remetente e Destinatário}
IdMessage.From.Address := DeEmail;
IdMessage.From.Text := DeNome + '';
IdMessage.ReplyTo.EMailAddresses := DeEmail;
IdMessage.Recipients.EMailAddresses := Trim(Para);
if AutoResposta then begin
IdMessage.ReceiptRecipient.Text := DeEmail;
end;
IdMessage.Subject := Trim( Assunto );
{Adiciona o CORPO da Mensagem}
IdCorpo := TIdText.Create(IdMessage.MessageParts,nil);
IdCorpo.ContentType := EmailTipoMIME(CorpoMIME);
IdCorpo.ContentDescription := 'multipart-1';
IdCorpo.CharSet := 'ISO-8859-1';
IdCorpo.ContentTransfer := '16bit';
IdCorpo.ContentDescription := 'Corpo da Mensagem';
IdCorpo.Body.Clear;
IdCorpo.Body.Add( Corpo );
IdSMTP := TIdSMTP.Create(nil);
if Porta = '25' then begin
With IdSMTP Do begin
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create( nil );
IdSMTP.IOHandler := IdSSL;
UseTLS := utUseImplicitTLS;
except
on E: Exception do begin
IOHandler := TIdIOHandler.MakeDefaultIOHandler( nil );
UseTLS := utNoTLSSupport;
ShowMessage('SSL da Autenticação Segura Falhou.' + #13 + '' + #13 +
'Pode ser uma instabilidade temporária na ' + #13 +
'conexão de sua Internet.' + #13 + '' +#13+
'Tente de novo agora ou mais tarde.');
result := False;
end;
end;
IdSSL.SSLOptions.Method := sslvSSLv2;
IdSSL.SSLOptions.Mode := sslmClient;
end;
end;
With IdSMTP Do
try
AuthType := SatDefault;
ReadTimeout := 10000;
Host := Dominio;
Port := StrToInt(Porta);
UserName := Usuario;
Password := Senha;
try
Connect;
Authenticate;
except
on E: Exception do begin
ShowMessage('Autenticação Falhou.' +#13+ '' + #13 +
'Verifique seu Nome de Usuário e Senha ou '+#13+
'Tente de novo agora ou mais tarde.');
result := False;
end;
end;
if Connected then begin
Send( IdMessage );
result := True;
end else begin
raise Exception.Create('A conexão com o Provedor foi interrompida.' + #13 + '' + #13 +
'Verifique se a sua Internet está ativa.');
result := False;
end;
finally
Disconnect;
end;
except
result := false;
end;
finally
FreeAndNil( IdMessage );
FreeAndNil( IdSMTP );
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Close;
end;
end.
x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*
Desde já agradeço a atenção de todos.
Eliel G. Martins
Eliel Martins
Curtidas 0
Respostas
Eliel Martins
11/12/2009
Pessoal, esqueci de referênciar que estou utilizando o Delphi 2009 e o componente Indy nativo do Delphi 2009 ...
Valeu pessoal, aguardo um retorno ...
Valeu pessoal, aguardo um retorno ...
GOSTEI 0
Thiago Silva
11/12/2009
Boa noite.. tive o msm problema.. pesquisei pra cacete.. perdi bastante tempo, mas por fim devido a necessidade, desisti e meu cliente criou email em outro provedor..
Tow na torcida por uma solução aqui tb...
GOSTEI 0
Gustavo Magalhães
11/12/2009
Bom dia,
alguém conseguiu resolver esse problema e enviar e-mail via hotmail?
Obrigado
alguém conseguiu resolver esse problema e enviar e-mail via hotmail?
Obrigado
GOSTEI 0
Leandro
11/12/2009
Delphi 7 funcionava mandar.... quando necessitava de atenticação no delphi 2010 tambem não consegui falta uma propriedade que existia no delphi 7... nao me lembro qual tambem
hehehehe
GOSTEI 0
Lartedesign
11/12/2009
Ola ...
Amigos sigao essas dicas : (AUTO EXPLICATIVA)
Servidor POP: pop3.live.com (Porta 995) POP SSL É NECESSARIO ? SIM USUARIO : utilize no usuario da seguinte fotma meuemail@hotmail.com Password: Use a senha do seu próprio email (óbvio)
Servidor SMTP : smtp.live.com (Porta 25) DICA : Se a porta 25 estiver bloqueada (e comum estar) use o SMTP com a porta 587 utilizando TLS ou SSL dependendo do caso (teste com suas necessidades) Autenticação é Necessária? SIM TLS/SSL Necessário ? SIM
siga estas dicas e acredito que nao ira ter problemas ...
organize seus componentes ... se obtiver sucesso
poste aqui se nao poste tbmm
espero ter ajudado
ATT
lartedesign
Leandro
Amigos sigao essas dicas : (AUTO EXPLICATIVA)
Servidor POP: pop3.live.com (Porta 995) POP SSL É NECESSARIO ? SIM USUARIO : utilize no usuario da seguinte fotma meuemail@hotmail.com Password: Use a senha do seu próprio email (óbvio)
Servidor SMTP : smtp.live.com (Porta 25) DICA : Se a porta 25 estiver bloqueada (e comum estar) use o SMTP com a porta 587 utilizando TLS ou SSL dependendo do caso (teste com suas necessidades) Autenticação é Necessária? SIM TLS/SSL Necessário ? SIM
siga estas dicas e acredito que nao ira ter problemas ...
organize seus componentes ... se obtiver sucesso
poste aqui se nao poste tbmm
espero ter ajudado
ATT
lartedesign
Leandro
GOSTEI 0