Anexar imagem num campo MEMO (E-mail)
-----------------------------------------------------------------------------------
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute = true then
begin
if OpenPictureDialog1.FileName <> ´´ then
begin
Memo1.Lines.Add(´
´);
end
end;
end;
-----------------------------------------------------------------------------------
Anexo a imagem Jpeg, e quando envio, a imagem não aparece na visualização do e-mail... Como que eu poderia fazer isto? Se eu deixo este código como está abaixo, aí dá certo, mas quero colocar num button, pra buscar a imagem...
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach.ContentDisposition := ´inline´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts,´imagem1.jpg´);
newAttach.ExtraHeaders.Values[´Content-ID´] := ´imagem1.jpg´;
Desde já, agradeço!
Lucas_spohr
Respostas
Lucas_spohr
12/09/2007
Memo1.Lines.Add(´<br><IMG SRC=´´+OpenPictureDialog1.FileName + ´´>´);
Massuda
12/09/2007
Lucas_spohr
12/09/2007
mas neste exemplo, a imagem está no código mesmo...
Eu gostaria de anexar, manualmente mesmo, clicando no button, escolhendo a imagem e anexando no topo do campo da mensagem...
de qualquer forma, obrigado...
Massuda
12/09/2007
Lucas_spohr
12/09/2007
Pois bem, este é o meu código do button, que fará a busca da imagem Jpeg, bmp, o que for...
--------------------------------------------------------------------------------
if OpenPictureDialog1.Execute = true then
begin
if OpenPictureDialog1.FileName <> ´´ then
begin
Memo1.Lines.Add(´<br><IMG SRC=´´+OpenPictureDialog1.FileName + ´´>´);
end
end;
--------------------------------------------------------------------------------
anexo ela, envio meu e-mail, só que, ao visualizar no hotmail ou no outlook, ela não aparece!! é assim que o cliente precisa: clicar no botão, escolher a imagem e ela, ficará no topo... o código acima, não funciona... mas este código abaixo, funciona...
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach.ContentDisposition := ´inline´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts,´imagem1.jpg´);
newAttach.ExtraHeaders.Values[´Content-ID´] := ´imagem1.jpg´;
Como que eu poderia implementar o button para buscar a imagem?
Obrigado.
Martins
12/09/2007
// Anexa a imagem ao corpo do email newText := TIdText.Create(IdMessage.MessageParts); newText.ContentType := ´text/plain´; newAttach.ContentDisposition := ´inline´; newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName); newAttach.ExtraHeaders.Values[´Content-ID´] := ExtractFileName(OpenPictureDialog1.FileName);
Assim não funciona também?
Lucas_spohr
12/09/2007
-----------------------------------------------------------------------
procedure TForm1.Button2Click(Sender: TObject);
begin
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach.ContentDisposition := ´inline´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ExtraHeaders.Values[´Content-ID´] := ExtractFileName(OpenPictureDialog1.FileName);
end;
-----------------------------------------------------------------------
No seu código, tinha faltado um ´)´, mas corrigi...
mas agora, quando clico no button para anexar, dá essa msg:
´Project Project1.exe raised exception class EAccessViolation with message ´Access violation at address 08071.... in module......´
ñ tá fácil isso!! heheh
Obrigado...
Martins
12/09/2007
Esse código q vc diz q funciona.
// Anexa a imagem ao corpo do email newText := TIdText.Create(IdMessage.MessageParts); newText.ContentType := ´text/plain´; newAttach.ContentDisposition := ´inline´; newAttach := TIdAttachment.Create(IdMessage.MessageParts,´imagem1.jpg´); newAttach.ExtraHeaders.Values[´Content-ID´] := ´imagem1.jpg´;
Ele está em um Button?
vc não poderia criar uma variável q armazene essa imagem?
Lucas_spohr
12/09/2007
Resumindo, está como se fosse assim:
procedure TForm1.btnEnviarEmailClick(Sender: TObject);
begin
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach.ContentDisposition := ´inline´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ExtraHeaders.Values[´Content-ID´] := ExtractFileName(OpenPictureDialog1.FileName);
end;
end;
é claro, no código acima, está faltando o SMTP.Connect/Disconnect, etc, etc... hehe
já no button IMAGEM, o código está assim:
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute = true then
begin
if OpenPictureDialog1.FileName <> ´´ then
begin
Memo1.Lines.Add(´<br><IMG SRC=´´+OpenPictureDialog1.FileName + ´´>´);
end;
end;
end;
Pelo que eu estou interpretando pelo q vc me passou, é o seguinte:
Clico no button IMAGEM, o Opendialog irá executar e escolherei minha imagem... daí quando clico no button ENVIAR, irá anexar no MEMO a imagem que escolhi do OpenDialog, e pronto...
é mais ou menos por aí?
Obrigado...
Martins
12/09/2007
No envio?
Lucas_spohr
12/09/2007
eu anexo a imagem e o caminho da imagem, até aparece no MEMO... mas depois quando vou enviar o e-mail, aí da o erro...
Lucas_spohr
12/09/2007
tooda minha aplicação ficou assim:
[i:236f6ec870]
procedure TForm1.EnviarClick(Sender: TObject);
begin
// Endereço e ID das Imagens
imgName1 := ExtractFileName(OpenPictureDialog1.FileName);
assinatura := ExtractFileName(OpenDialog1.FileName);
// Mensagem
IdMessage.Subject := edtAssunto.Text;
// Adiciona uma parte texto ao corpo
newText := TIdText.Create(IdMessage.MessageParts,nil);
newText.ContentType := ´text/plain´;
// Anexa a primeira imagem
newAttach := TIdAttachment.Create(IdMessage.MessageParts,imgName1);
newAttach.ContentType := ´image/jpeg´;
newAttach.ContentDisposition := ´inline´;
newAttach.ExtraHeaders.Values[´Content-ID´] := ´<´+imgId1+´>´;
// Anexa a assinatura
//newAttach := TIdAttachment.Create(IdMessage.MessageParts,assinatura);
//newAttach.ContentType := ´text/plain´;
//newAttach.ContentDisposition := ´inline´;
//newAttach.ExtraHeaders.Values[´Content-ID´] := ´<´+assinatura+´>´;
//EmailContent.BodyText := ....
newText := TIdText.Create(IdMessage.MessageParts);
newText.Body.Text := Memo1.Text;
newText.ContentType := ´text/plain´;
// Remetente
idMessage.From.Address := edtEmailRem.Text;
idMessage.From.Name := edtNomeRem.Text;
// Destinatario
idMessage.Recipients.EMailAddresses := edtEmailDes.Text;
// Autenticacao - Use apenas quando o servidor exigir
idSMTP.AuthenticationType := atLogin;
idSMTP.Username := edtUsuario.Text;
idSMTP.Password := edtSenha.Text;
// Dados do Servidor
idSMTP.Host := edtHostSMTP.Text;
idSMTP.Port := 25;
idSMTP.Connect;
try
idSMTP.Send(IdMessage);
FreeAndNil(newText);
FreeAndNil(newAttach);
finally
idSMTP.Disconnect;
end;
end;
procedure TForm1.ImagemClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute = true then
begin
if OpenPictureDialog1.FileName <> ´´ then
begin
Memo1.Lines.Add(´<br><IMG SRC=´´+OpenPictureDialog1.FileName + ´´>´);
end;
end;
end;
procedure TForm1.AssinaturaClick(Sender: TObject);
begin
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;
end;
end;
end.[/i:236f6ec870]
Agora, falta a assinatura!! clico no button pra colocar a assinatura, no memo ela aparece, porém, na hora de enviar por e-mail, na visualização, ela não aparece... como faze??
obrigado...
Martins
12/09/2007
Como está seu código para adição da assinatura no e-mail?
Lucas_spohr
12/09/2007
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
Memo1.Lines.LoadFromFile(´<br><body=´´+ OpenDialog1.FileName + ´´>´);
end;
end;
end;
Lucas_spohr
12/09/2007
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
[i:b18a163ade] //Nesta linha de baixo, estava Memo1.Lines.LoadFromFile, hehe[/i:b18a163ade]
Memo1.Lines.Add(´<br><strong=´´+ OpenDialog1.FileName +´´>´);
end;
end;
end;
Mas ainda está dando erro, na hora de enviar o e-mail... :oops: :cry:
o erro é nesta parte:
btnEnviar:
[i:b18a163ade]// Dados do Servidor
idSMTP.Host := edtHostSMTP.Text;
idSMTP.Port := 25;
idSMTP.Connect;
try
idSMTP.Send(IdMessage);
FreeAndNil(newText);
FreeAndNil(newAttach);
ShowMessage(´E-mail enviado com sucesso!´);
finally
idSMTP.Disconnect;
Form1.Close;
end;[/i:b18a163ade]
Project Project1.exe raised exception class EFOpenError with message ´Cannot open file ´´. O sistema não pode encontrar o caminho especificado....´
alguém faz idéia??
e ainda não sei se é exatamente assim esta parte, para colocar o arquivo do OpenDialog, se é strong, etc, etc:
(´<br><strong=´´+ OpenDialog1.FileName +´´>´);
tá difícil!!
Obrigado pessoal... Mas ainda falta coisas!! hehe[/i]
Lucas_spohr
12/09/2007
mas o erro, é no FreeAndNill do btnEnviar
Martins
12/09/2007
try idSMTP.Send(IdMessage); ShowMessage(´E-mail enviado com sucesso!´); FreeAndNil(newText); FreeAndNil(newAttach);
...
Tá dando um erro ao abrir o arquivo.
FreeAndNil(newText); FreeAndNil(newAttach);
essa parte não deveria ficar após Finally?
Dá o mesmo erro?
Lucas_spohr
12/09/2007
mudei os códigos, e agora, é o seguinte...
Tenho o seguinte código, no button enviar do meu form de e-mail:
-----------------------------------------------------------------------------
procedure TForm1.btnEnviarClick(Sender: TObject);
var
newText : TIdText;
newAttach : TIdAttachment;
begin
// Configura o Email.
try
with IdMessage do
begin
From.Text := edtEmailRem.Text;
Recipients.EMailAddresses := edtEmailDes.Text;
Subject := edtAssunto.Text;
Body.Assign(Memo1.Lines);
end;
// Imagem HTML
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType:=´text/html´;
newText.Body.Add(´<IMG SRC=´cid:´ + ExtractFileName(OpenPictureDialog1.FileName) + ´´>´);
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts, pchar(ExtractFileName(OpenPictureDialog1.FileName)));
newAttach.ExtraHeaders.Values[´Content-ID´] := pchar(ExtractFileName(OpenPictureDialog1.FileName));
// Envia o Email.
with IdSMTP do
begin
AuthenticationType := atLogin;
Host := edtHostSMTP.Text;
Port := 25;
Username := edtUsuario.Text;
Password := edtSenha.Text;
try
Connect;
Send(IdMessage);
ShowMessage(´Mensagem enviada com sucesso!´);
Close;
finally
if Connected then
Disconnect;
end;
end;
finally
end;
end;
-----------------------------------------------------------------------------
Deixando desta maneira, ao enviar um texto normalmente, dá erro:
´Cannot open file ´´. O sistema não pode encontrar o caminho especificado´.´
Daí, eu comento as seguintes linhas, que são para anexar a imagem ao corpo, aí eu consigo enviar texto:
{
// Imagem HTML
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType:=´text/html´;
newText.Body.Add(´<IMG SRC=´cid:´ + ExtractFileName(OpenPictureDialog1.FileName) + ´´>´);
// Anexa a imagem ao corpo do email
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/plain´;
newAttach := TIdAttachment.Create(IdMessage.MessageParts, pchar(ExtractFileName(OpenPictureDialog1.FileName)));
newAttach.ExtraHeaders.Values[´Content-ID´] := pchar(ExtractFileName(OpenPictureDialog1.FileName));
}
A pergunta:
O que que eu precisaria acrescentar para ser possível o envio ao mesmo tempo, tanto de imagem quanto de texto? Seria algum código HTML, para o texto também?
Obrigado.
Lucas_spohr
12/09/2007
Lucas_spohr
12/09/2007
Adicionar a imagem sempre beem em cima do memo, e a assinatura, bem embaixo, simulando a ´Nova Mensagem´ do Outlook...
Como que eu poderia fazer?
por exemplo...
MEMO
------------------------------------------------------------
C:\imagens\imagem.jpg
texto texto texto
texto texto texto
texto texto texto
Lucas Rafael Spohr
Profissão
------------------------------------------------------------
ou seja...
independente de eu clicar primeiro em assinatura e inserir, a assinatura deverá ter a obrigação de ficar sempre por último, bem embaixo. Se eu clicar em Imagem, esta deverá obedecer a regra e ficar bem em cima... Depois que eu mandar o e-mail, na visualização, deverá ficar como se fosse um e-mail do outlook!
Grato...
Lucas_spohr
12/09/2007
consegui colocar a imagem no topo:
------------------------------------------------------------------------------
procedure TForm1.btnImagemClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute = true then
begin
if OpenPictureDialog1.FileName <> ´´ then
begin
// Primeira linha do Memo recebe a imagem buscada do OpenPicture...
Memo1.Lines[0] := OpenPictureDialog1.FileName;
end;
end;
end;
------------------------------------------------------------------------------
E agora, para adicionar a assinatura beem embaixo, como eu faço?
Obrigado.
Martins
12/09/2007
Continuamos com o problema da assinatura?
Lucas_spohr
12/09/2007
tenho que adicionar o conteúdo do ´assinatura.txt´, na última linha do memo... como q eu poderia fazer?
Grato.
Martins
12/09/2007
Está em um arquivo TXT? Vc não poderia ler o conteúdo dele e jogar no memo?
Lucas_spohr
12/09/2007
isso eu já fiz... mas o que eu preciso fazer, é deixar o conteúdo do TXT na última linha do memo...
No MEMO, deve ser obedecida uma regra:
1º. IMAGEM
2º. CONTEÚDO-TEXTO
3º. ASSINATURA (é aí que eu me refiro... essa assinatura, deve estar sempre por último)
é isso aí... acho que agora, está bem explicado...
Obrigado pela atenção!
Lucas_spohr
12/09/2007
além disso, como que eu faço para, no Outlook, aparecer a minha mensagem enviada pelo projeto, em ítens enviados?
é possível isso, usando INDY??
Grato.
Staurosg3
12/09/2007
Lucas_spohr
12/09/2007
Abaixo, o código do projeto que eu fiz... Mas não se esqueça de atualizar o INDY... 9.0.18, se eu não me engano, é a versão...
procedure TForm1.btnEnviarClick(Sender: TObject);
var
newText : TIdText;
newAttach : TIdAttachment;
i: integer;
begin
// Configura o Servidor
IdSMTP.Username := edtUsuario.text;
IdSMTP.Password := edtSenha.text;
IdSMTP.Host := edtHostSMTP.text;
IdSMTP.Port := 25;
// Configura o Remetente da Mensagem
IdMessage.Clear;
IdMessage.Subject := edtAssunto.Text;
IdMessage.From.Address := edtEmailRem.Text;
IdMessage.From.Name := edtNomeRem.Text;
// Configura os destinatários
IdMessage.Recipients.Clear;
IdMessage.Recipients.EMailAddresses := edtEmailDes.Text; //Para
IdMessage.CCList.EMailAddresses := edtEmailRem.Text; //Cóp. da msg p/ rem.
// Configura os anexos, caso tiver
for i := 0 to lbAnexos.Items.Count-1 do
TIdAttachment.Create(IdMessage.MessageParts, lbAnexos.Items[i]);
// Confirmação de Leitura
begin
if cbConfirma.Checked then
IdMessage.ReceiptRecipient.Address := edtEmailRem.Text;
end;
// Adiciona o TEXTO ao corpo da mensagem
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/html´;
newText.Body.Add(´<HTML>´);
newText.Body.Add(´<BODY>´);
if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´´)
// Se não quizer anexar imagem, mas anexar um HTML
// Para envio de Mala Direta, então...
else
newText.Body.LoadFromFile(OpenDialog2.FileName);
for i := 0 to RichEdit1.Lines.Count-1 do
begin
newText.Body.Add(RichEdit1.Lines.Strings[i]+´
´);
end;
newText.Body.Add(´´);
newText.Body.Add(´</BODY>´);
newText.Body.Add(´</HTML>´);
//Anexa a imagem ao corpo do E-mail
if OpenPictureDialog1.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ContentType := ´image/jpeg´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenPictureDialog1.FileName)+ ´>´);
end;
// Adiciona uma parte texto ao corpo
newText := TIdText.Create(IdMessage.MessageParts,nil);
newText.ContentType := ´text/plain´;
newText.Body.Add(´Este email só será visualizado em padrão HTML´);
// Usar o ProgressBar
begin
i := 0;
for i := ProgressBar1.Min to ProgressBar1.Max do
begin
ProgressBar1.Position := i;
Sleep(30);
end
end;
// Envia o Email.
with IdSMTP do
begin
AuthenticationType := atLogin;
try
Connect;
Send(IdMessage);
ShowMessage(´Mensagem enviada com sucesso!´);
finally
if Connected then
lbAnexos.Clear;
Disconnect;
end;
end;
end;
procedure TForm1.btnAssinaturaClick(Sender: TObject);
var
t : TStringList;
begin
t := TStringList.create;
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
t.LoadFromFile(OpenDialog1.FileName);
RichEdit1.Lines.AddStrings(t);
end;
end;
end;
procedure TForm1.btnImagemClick(Sender: TObject);
begin
OpenPictureDialog1.Execute;
end;
Lucas_spohr
12/09/2007
procedure TForm1.btnEnviarClick(Sender: TObject);
var
newText : TIdText;
newAttach : TIdAttachment;
i: integer;
begin
// Configura o Servidor
IdSMTP.Username := edtUsuario.text;
IdSMTP.Password := edtSenha.text;
IdSMTP.Host := edtHostSMTP.text;
IdSMTP.Port := 25;
// Configura o Remetente da Mensagem
IdMessage.Clear;
IdMessage.Subject := edtAssunto.Text;
IdMessage.From.Address := edtEmailRem.Text;
IdMessage.From.Name := edtNomeRem.Text;
// Configura os destinatários
IdMessage.Recipients.Clear;
IdMessage.Recipients.EMailAddresses := edtEmailDes.Text; //Para
IdMessage.CCList.EMailAddresses := edtEmailRem.Text; //Cóp. da msg p/ rem.
// Configura os anexos, caso tiver
for i := 0 to lbAnexos.Items.Count-1 do
TIdAttachment.Create(IdMessage.MessageParts, lbAnexos.Items[i]);
// Confirmação de Leitura
begin
if cbConfirma.Checked then
IdMessage.ReceiptRecipient.Address := edtEmailRem.Text;
end;
// Adiciona o TEXTO ao corpo da mensagem
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/html´;
newText.Body.Add(´<HTML>´);
newText.Body.Add(´<BODY>´);
if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´<IMG SRC=´cid:´+ ExtractFileName(OpenPictureDialog1.FileName) +´´>´)
// Se não quizer anexar imagem, mas anexar um HTML
// Para envio de Mala Direta, então...
else
newText.Body.LoadFromFile(OpenDialog2.FileName);
for i := 0 to RichEdit1.Lines.Count-1 do
begin
newText.Body.Add(RichEdit1.Lines.Strings[i]+´<BR>´);
end;
newText.Body.Add(´</P>´);
newText.Body.Add(´</BODY>´);
newText.Body.Add(´</HTML>´);
//Anexa a imagem ao corpo do E-mail
if OpenPictureDialog1.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ContentType := ´image/jpeg´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenPictureDialog1.FileName)+ ´>´);
end;
{
//Anexa o HTML ao corpo do E-mail
if OpenDialog2.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenDialog2.FileName));
newAttach.ContentType := ´text/html´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenDialog2.FileName)+ ´>´);
end;
}
// Adiciona uma parte texto ao corpo
newText := TIdText.Create(IdMessage.MessageParts,nil);
newText.ContentType := ´text/plain´;
newText.Body.Add(´Este email só será visualizado em padrão HTML´);
// Usar o ProgressBar
begin
i := 0;
for i := ProgressBar1.Min to ProgressBar1.Max do
begin
ProgressBar1.Position := i;
Sleep(30);
end
end;
// Envia o Email.
with IdSMTP do
begin
AuthenticationType := atLogin;
try
Connect;
Send(IdMessage);
ShowMessage(´Mensagem enviada com sucesso!´);
finally
if Connected then
lbAnexos.Clear;
Disconnect;
end;
end;
end;
procedure TForm1.btnAssinaturaClick(Sender: TObject);
var
t : TStringList;
begin
t := TStringList.create;
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
t.LoadFromFile(OpenDialog1.FileName);
RichEdit1.Lines.AddStrings(t);
end;
end;
end;
procedure TForm1.btnImagemClick(Sender: TObject);
begin
OpenPictureDialog1.Execute;
end;
Lucas_spohr
12/09/2007
procedure TForm1.btnEnviarClick(Sender: TObject);
var
newText : TIdText;
newAttach : TIdAttachment;
i: integer;
begin
// Configura o Servidor
IdSMTP.Username := edtUsuario.text;
IdSMTP.Password := edtSenha.text;
IdSMTP.Host := edtHostSMTP.text;
IdSMTP.Port := 25;
// Configura o Remetente da Mensagem
IdMessage.Clear;
IdMessage.Subject := edtAssunto.Text;
IdMessage.From.Address := edtEmailRem.Text;
IdMessage.From.Name := edtNomeRem.Text;
// Configura os destinatários
IdMessage.Recipients.Clear;
IdMessage.Recipients.EMailAddresses := edtEmailDes.Text; //Para
IdMessage.CCList.EMailAddresses := edtEmailRem.Text; //Cóp. da msg p/ rem.
// Configura os anexos, caso tiver
for i := 0 to lbAnexos.Items.Count-1 do
TIdAttachment.Create(IdMessage.MessageParts, lbAnexos.Items[i]);
// Confirmação de Leitura
begin
if cbConfirma.Checked then
IdMessage.ReceiptRecipient.Address := edtEmailRem.Text;
end;
// Adiciona o TEXTO ao corpo da mensagem
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/html´;
newText.Body.Add(´<HTML>´);
newText.Body.Add(´<BODY>´);
if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´<IMG SRC=´cid:´+ ExtractFileName(OpenPictureDialog1.FileName) +´´>´)
// Se não quizer anexar imagem, mas anexar um HTML
// Para envio de Mala Direta, então...
else
newText.Body.LoadFromFile(OpenDialog2.FileName);
for i := 0 to RichEdit1.Lines.Count-1 do
begin
newText.Body.Add(RichEdit1.Lines.Strings[i]+´<BR>´);
end;
newText.Body.Add(´</P>´);
newText.Body.Add(´</BODY>´);
newText.Body.Add(´</HTML>´);
//Anexa a imagem ao corpo do E-mail
if OpenPictureDialog1.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ContentType := ´image/jpeg´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenPictureDialog1.FileName)+ ´>´);
end;
{
//Anexa o HTML ao corpo do E-mail
if OpenDialog2.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage.MessageParts, ExtractFileName(OpenDialog2.FileName));
newAttach.ContentType := ´text/html´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenDialog2.FileName)+ ´>´);
end;
}
// Adiciona uma parte texto ao corpo
newText := TIdText.Create(IdMessage.MessageParts,nil);
newText.ContentType := ´text/plain´;
newText.Body.Add(´Este email só será visualizado em padrão HTML´);
// Usar o ProgressBar
begin
i := 0;
for i := ProgressBar1.Min to ProgressBar1.Max do
begin
ProgressBar1.Position := i;
Sleep(30);
end
end;
// Envia o Email.
with IdSMTP do
begin
AuthenticationType := atLogin;
try
Connect;
Send(IdMessage);
ShowMessage(´Mensagem enviada com sucesso!´);
finally
if Connected then
lbAnexos.Clear;
Disconnect;
end;
end;
end;
procedure TForm1.btnAssinaturaClick(Sender: TObject);
var
t : TStringList;
begin
t := TStringList.create;
if OpenDialog1.Execute = true then
begin
if OpenDialog1.FileName <> ´´ then
begin
t.LoadFromFile(OpenDialog1.FileName);
RichEdit1.Lines.AddStrings(t);
end;
end;
end;
procedure TForm1.btnImagemClick(Sender: TObject);
begin
OpenPictureDialog1.Execute;
end;
Staurosg3
12/09/2007
Lucas_spohr
12/09/2007
[i:7aa38b7541]if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´´)
else
newText.Body.LoadFromFile(OpenDialog2.FileName);
for i := 0 to RichEdit1.Lines.Count-1 do
begin
newText.Body.Add(RichEdit1.Lines.Strings[i]+´
´);
end; [/i:7aa38b7541]
nessa parte do código, vc pode ver que primeiro foi adicionada a linha que pega o conteúdo do OpenPictureDialog e depois, pega o conteúdo do que foi escolhido do OpenDialog... Para fazer da forma que vc quer, é só alterar a ordem, ou seja: colocar primeiro o LoadFromFile (opendialog2....) e em seguida, colocar o openpicturedialog1...
espero que tenha sido claro...
Staurosg3
12/09/2007
// Adiciona o TEXTO ao corpo da mensagem
newText := TIdText.Create(IdMessage1.MessageParts);
newText.ContentType := ´text/html´;
newText.Body.Add(´<HTML>´);
newText.Body.Add(´<BODY>´);
if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´<IMG SRC=´cid:´+ ExtractFileName(OpenPictureDialog1.FileName) +´´>´);
newText.Body.Add(´Este email só será visualizado em padrão HTML´);
newText.Body.Add(mmoMsg.Lines.Text+´<BR>´);
newText.Body.Add(´</P>´);
newText.Body.Add(´</BODY>´);
newText.Body.Add(´</HTML>´);
//Anexa a imagem ao corpo do E-mail
if OpenPictureDialog1.FileName <> ´´ then
begin
newAttach := TIdAttachment.Create(IdMessage1.MessageParts, ExtractFileName(OpenPictureDialog1.FileName));
newAttach.ContentType := ´image/jpeg´;
newAttach.Headers.Add(´Content-ID: <´ +ExtractFileName(OpenPictureDialog1.FileName)+ ´>´);
end;
Se eu coloco a linha de comando da imagem o texto some ai só aparece a imagem no email , deve ser algum erro na estrutura do HTML, mas ai eu não sei o que é, dá pra me ajudar...
Staurosg3
12/09/2007
Lucas_spohr
12/09/2007
// Adiciona o TEXTO ao corpo da mensagem
newText := TIdText.Create(IdMessage.MessageParts);
newText.ContentType := ´text/html´;
newText.Body.Add(´<HTML>´);
newText.Body.Add(´<BODY>´);
if OpenDialog2.FileName <> ´´ then
newText.Body.LoadFromFile(OpenDialog2.FileName);
for i:=0 to RichEdit1.Lines.Count-1 do
begin
newText.Body.Add(RichEdit1.Lines.Strings[i]+´<BR>´)
end;
begin
if OpenPictureDialog1.FileName <> ´´ then
newText.Body.Add(´<IMG SRC=´cid:´+ ExtractFileName(OpenPictureDialog1.FileName) +´´>´);
end;
newText.Body.Add(´</P>´);
newText.Body.Add(´</BODY>´);
newText.Body.Add(´</HTML>´);
Staurosg3
12/09/2007
Deu certo aqui também... a muito tempo procurava como fazer isso...
Agora é pesquisar para fazer um editor que possibilite editar o texto assim como no outlook....
mais uma vez obrigado
Staurosg3
12/09/2007
Além do codigo precisa setar alguma propriedade do componente???
Lucas_spohr
12/09/2007
// Confirmação de Leitura
begin
if ComboBox.Checked then
IdMessage.ReceiptRecipient.Address := edtEmailRemetente.Text;
end;
Mas uma observação:
Eu também fiquei um tempão tentando descobrir o problema disso... Mas, ao enviar um e-mail pelo seu projeto para um contato do hotmail, por exemplo; ao abrir este e-mail pelo hotmail, não aparecerá a mensagem de confirmação de leitura... Mas tendo este código, funcionará! Pode testar, enviando e-mails para outros endereços... tente no yahoo, etc, etc... não sei se funcionará, mas tente...
Lucas_spohr
12/09/2007
Staurosg3
12/09/2007
já que estou aqui vou ressuscitar esse topico pois estou tendo problemas com seviços de webmail, principalmente o gmail, pois quando recebe o email não aperece o texto apenas o anexo, mas se descarrega no outlook, fica normal.
alguém ae já teve esse problema se teve conseguiu solucionar?