Thema: Delphi Mailto mit Anhang senden

Einzelnen Beitrag anzeigen

Benutzerbild von Kroko1999
Kroko1999

Registriert seit: 21. Apr 2005
Ort: Spremberg
455 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: Mailto mit Anhang senden

  Alt 4. Feb 2008, 14:58
oder Du nimmst folgende Unit:
Delphi-Quellcode:
unit tdEmail;

interface

uses
  Classes, SysUtils;

function SendEMail(const AHost,AUser,APass, AToAdress,ASubject: String;
                   const ABody,AAttachment: TStrings): Integer;

implementation

uses
  IdMessage, IdSMTP, idAttachmentFile;

function SendEMail(const AHost,AUser,APass, AToAdress,ASubject: String;
                   const ABody,AAttachment: TStrings): Integer;
var
  HMsg: TIdMessage;
  HSMTP: TIdSMTP;
  I: Integer;
begin
  Result := 0; { Ok }
  HSMTP := TIdSMTP.Create(nil);
  HSMTP.Host := AHost;
  HSMTP.Username := AUser;
  HSMTP.Password := APass;
  HSMTP.Port := 25;
  HSMTP.AuthType := atDefault;
  HSMTP.Connect;
  { Message füllen }
  HMsg := TIdMessage.Create(nil);

  HMsg.From.Address := AUser;

  HMsg.Recipients.EMailAddresses := AToAdress;

  HMsg.Subject := ASubject;
  HMsg.Body.Clear;
  HMsg.Body.Assign(ABody);
  HMsg.Date := Now;
  { Anhang }
  if Assigned(AAttachment) then
    begin
      for I := 0 to AAttachment.Count - 1 do
        TIdAttachmentFile.Create(HMsg.MessageParts,AAttachment[I]);
    end;
  try
    try
      HSMTP.Send(HMsg);
    except
      Result := HSMTP.LastCmdResult.NumericCode;
    end;
  finally
    { frei geben }
    HMsg.Free;
    HSMTP.Free;

  end;
end;

end.
leider unkommentiert,
Da sprach der Stumme zum Blinden: "Du wirst sehen ..."
oder
Wer lesen kann, ist klar im Vorteil!
  Mit Zitat antworten Zitat