1
The following error appears when trying to execute the send email function:
Não há um programa padrão de e-mail associado para realizar a ação solicitada. instale um programa de e-mail ou, caso já exista um instalado, crie uma associação no painel de controle Programas Padrão.
Follows the code:
procedure TfrmEnviaEmail.btnEnviarClick(Sender: TObject);
var
i: integer;
IdAttachmentFile1 : TIdAttachmentFile;
IdUserPassProvider: TIdUserPassProvider;
idSASLLogin: TIdSASLLogin;
begin
IdSMTP1.ConnectTimeout := 30000;
IdSMTP1.ReadTimeout := 30000;
try
// cancelar:= false;
Screen.Cursor:= crHourGlass;
btnEnviar.Enabled:= false;
if cbDominio.ItemIndex = 0 then //anibaltec
begin
IdSMTP1.Host := 'anibaltec.com.br';
end;
if cbDominio.ItemIndex = 1 then //gmail
begin
IdSMTP1.Host := 'smtp.gmail.com';
end;
if cbDominio.ItemIndex = 2 then //hotmail
begin
IdSMTP1.Host := 'smtp.live.com';
end;
if cbDominio.ItemIndex = 3 then //yahoo
begin
IdSMTP1.Host := 'smtp.mail.yahoo.com';
end;
if cbDominio.ItemIndex = 4 then //tef.net
begin
IdSMTP1.Host := 'tef.net.br';
end;
IdMessage1.Clear;
IdMessage1.MessageParts.Clear;
IdMessage1.IsEncoded := True;
IdMessage1.CharSet := 'iso-8859-1';
IdMessage1.Encoding := MeMIME;
IdMessage1.ConvertPreamble := True;
IdMessage1.Priority := mpNormal;
IdMessage1.Date := Now;
IdMessage1.From.Address := edtEmailDest.Text;
IdMessage1.Subject := EdtAssunto.Text;
IdMessage1.Body.Text := 'Este e-mail e um e-mail automatico, por favor nao responde-lo. Segue em anexo o relatório.';
IdMessage1.ContentType := 'multipart/mixed';
IdMessage1.Recipients.EMailAddresses := EdtPara.Text;
//recebimento de confirmação
IdMessage1.Headers.Add('Disposition-Notification-To: '+edtEmailDest.Text);
IdMessage1.ReceiptRecipient.Address := edtEmailDest.Text;
IdMessage1.ReceiptRecipient.User := edtEmailDest.Text;
IdMessage1.ReceiptRecipient.Text := IdMessage1.From.Text;
if ListBox1.Items.Count > 0 then
begin
for i:= 0 to ListBox1.Items.Count - 1 do
begin
if FileExists(ListBox1.Items[i]) then
begin
IdAttachmentFile1 := TIdAttachmentFile.Create(IdMessage1.MessageParts, ListBox1.Items[i]);
if ExtractFileExt(ListBox1.Items[i]) = 'ini' then
IdAttachmentFile1.ContentType := 'application/txt;'
else
IdAttachmentFile1.ContentType := 'application/'+ExtractFileExt(ListBox1.Items[i])+';';
IdAttachmentFile1.FileName := ExtractFileName(ListBox1.Items[i]);
end;
end;
end;
with idSMTP1 do
begin
try
Port := 587;
IOHandler := IdSSLIOHandlerSocketOpenSSL1;
UseTLS := utNoTLSSupport;
// UseTLS := utUseExplicitTLS;
// IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
IdSSLIOHandlerSocketOpenSSL1.PassThrough := true;
except
on E: Exception do
begin
IOHandler := TIdIOHandler.MakeDefaultIOHandler( nil );
UseTLS := utNoTLSSupport;
end;
end;
end;
if not IdSMTP1.Connected then
begin
try
IdSMTP1.AuthType := satDefault;
IdSMTP1.Username := edtEmailDest.Text;
IdSMTP1.Password := edtSenhaDest.Text;
IdSMTP1.ReadTimeout := 10000;
IdSMTP1.Connect;
IdSMTP1.Authenticate;
except
on e: Exception do frmprincipal.EscreveLog(caminholog, 'Aplicativo não conseguiu se comunicar com o servidor de e-mail! Erro: '+e.Message);
end;
end;
IdSMTP1.Send(IdMessage1);
if ListBox1.Items.Count > 0 then
begin
for i:= 0 to ListBox1.Items.Count - 1 do
begin
if FileExists(ListBox1.Items[i]) then
begin
try
if IdSMTP1.Connected then
begin
frmPrincipal.EscreveLog(caminholog, 'Email enviado com sucesso. ' +
'Relatório '+ListBox1.Items[i]+' em anexo');
end;
except
on e: Exception do frmPrincipal.EscreveLog(caminholog,
'Servidor de Email ('+IdSMTP1.Host+') não foi conectado');
end;
end;
end;
end;
finally
if IdSMTP1.Connected then
begin
frmPrincipal.StatusBar1.Panels[0].Text := 'Email enviado com sucesso.';
frmprincipal.EscreveLog(caminholog, 'Email enviado com sucesso.');
end
else
begin
frmprincipal.EscreveLog(caminholog, 'Aplicativo não conseguiu se comunicar com o servidor de e-mail!');
end;
Screen.Cursor:= crDefault;
IdSMTP1.Disconnect;
btnEnviar.Enabled:= true;
ListBox1.Clear;
Close;
end;
end;
Is there any way to do this via Delphi? do something similar in the register and such?
– Ramon Ruan
friend, have to send me an example?
– Ramon Ruan
Mechanic, man, the Indy uses some standard program or it uses the sending of email via Telnet? the machines of the customers are giving this error. It is interesting but, there is no Outlook on their machine. In short, should Indy use the tool contained in the Winsock.dll DLL and send the emails via telnet not? or am I talking nonsense? : P
– Ramon Ruan
@Ramonruan From a look over mapi. Here have an example for Delphi.
– stderr