Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Problem mit Indy9/SMTP - HTML Mails mit Anhang (https://www.delphipraxis.net/97732-problem-mit-indy9-smtp-html-mails-mit-anhang.html)

Adamo 15. Aug 2007 08:40


Problem mit Indy9/SMTP - HTML Mails mit Anhang
 
Ich habe ein Problem beim verschicken von HTML Mails mit Anhang.
Ich hole sie über POP3 ab, speichere die Mail in IdMessage und schicke sie dann über SMTP weiter.


Der Code recht simpel:

Delphi-Quellcode:
.
.
  POP.Connect;
  POP.Retrieve(0, Msg);
.
.

  IdSMTP1.AuthenticationType := atLogin; {Simple Login}

  IdSMTP1.Username := SmtpServerUser;
  IdSMTP1.Password := SmtpServerPassword;

  IdSMTP1.Host := SmtpServerName;
  IdSMTP1.Port := SmtpServerPort;


  Msg.Recipients.EMailAddresses := '****@***.de';
  IdSMTP1.Connect;
  try
    IdSMTP1.Send(Msg);
  finally
    IdSMTP1.Disconnect;
  end;
Was ankommst. Sieht dann aber so aus beim HTML Mails mit Anhang:

--=oreStuf_2altzzz1234sadvnqw3nerasdf
Content-Type: text/plain; charset=s-ascii"
Content-Transfer-Encoding: quoted-printable

Testststststts#+

Askj

Adlksj

Asdlkjh#








--=oreStuf_2altzzz1234sadvnqw3nerasdf
Content-Type: text/html; charset=s-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"> <meta name=Generator content="Microsoft Word 12 (filtered medium)"> <style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed

Die Muhkuh 15. Aug 2007 08:44

Re: Problem mit Indy9/SMTP - HTML Mails mit Anhang
 
Hi Adamo,
herzlich Willkommen in der Delphi-PRAXiS. :dp:

Es wäre noch gut zu wissen, wie du die TIdMessage "befüllst".

Adamo 15. Aug 2007 11:12

Re: Problem mit Indy9/SMTP - HTML Mails mit Anhang
 
Ich verwende die Demo von den Indy Komponenten.

Diese Zeile holt die Ursprugsmail vom Server und legt diese in IdMessage ab, sofern ich das richtig sehe.
'POP.Retrieve(lvHeaders.Selected.Index + 1, Msg);'

Dann wird die so gefüllte 'Msg'(vom Typ IdMessage) 1 zu 1 über SMTP weiterversendet an einen bestimmten Empfänger.
Diese kommt dann aber so wie oben gezeigt an.



Delphi-Quellcode:
procedure TfrmMain.RetrieveExecute(Sender: TObject);
var
   stTemp: string;
   intIndex: Integer;
   li: TListItem;
begin
   stTemp := Statusbar1.Panels[1].text;
   if lvHeaders.Selected = nil then
      begin
         Exit;
      end;
   //initialise
   Showbusy(true);
   Msg.Clear;
   Memo1.Clear;
   lvMessageParts.Items.Clear;
   From.Caption := '';
   Cc.Caption := '';
   Subject.Caption := '';
   Date.Caption := '';
   Receipt.Caption := '';
   Organization.Caption := '';
   Priority.Caption := '';
   pnlAttachments.visible := false;

   //get message and put into MSG
   ShowStatus('Retrieving message "' + lvHeaders.Selected.SubItems.Strings[3] + '"');
   POP.Retrieve(lvHeaders.Selected.Index + 1, Msg);
   statusbar1.Panels[0].text := lvHeaders.Selected.SubItems.Strings[3];

   //Setup fields on screen from MSG
   From.Caption := Msg.From.Text;
   Recipients.Caption := Msg.Recipients.EmailAddresses;
   Cc.Caption := Msg.CCList.EMailAddresses;
   Subject.Caption := Msg.Subject;
   Date.Caption := FormatDateTime('dd mmm yyyy hh:mm:ss', Msg.Date);
   Receipt.Caption := Msg.ReceiptRecipient.Text;
   Organization.Caption := Msg.Organization;
   Priority.Caption := IntToStr(Ord(Msg.Priority) + 1);

   //Setup attachments list
   ShowStatus('Decoding attachments (' + IntToStr(Msg.MessageParts.Count) + ')');
   for intIndex := 0 to Pred(Msg.MessageParts.Count) do
      begin
         if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then
            begin //general attachment
               pnlAttachments.visible := true;
               li := lvMessageParts.Items.Add;
               li.ImageIndex := 8;
               li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
               li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[intIndex]).ContentType);
            end
         else
            begin //body text
               if Msg.MessageParts.Items[intIndex] is TIdText then
                  begin
                     Memo1.Lines.Clear;
                     Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
                  end
            end;
      end;
   ShowStatus(stTemp);
   Showbusy(false);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:18 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz