AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Neuen Beitrag zur Code-Library hinzufügen Delphi email mit Anhängen verschicken (Indys)
Thema durchsuchen
Ansicht
Themen-Optionen

email mit Anhängen verschicken (Indys)

Ein Thema von smallsmoker · begonnen am 22. Aug 2008 · letzter Beitrag vom 10. Mär 2009
 
Benutzerbild von smallsmoker
smallsmoker

Registriert seit: 12. Nov 2007
Ort: Duisburg
283 Beiträge
 
#1

email mit Anhängen verschicken (Indys)

  Alt 22. Aug 2008, 18:23
hallo dp,
habe verzweifelt in der codelib etwas gesucht um emails aus einer anwendung mit anhang/anhängen zu versenden,
habe es dann selbst (mit hilfe der indy beispiele) in die hand genommen:

Es wird Indy 9 benötigt.
man muss
Delphi-Quellcode:
IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP
einbinden


Delphi-Quellcode:
const
  atNoLogin = 0;
  atSimpleLogin = 1;

procedure Sendemail(sender_email, recipent_email, email_subject: string;
                    email_text: tstrings; attachment_list: tstrings; //can be also attachment_list: tstringlist;
                    smtp_username, smtp_password, smtp_host: string;
                    const SmtpAuthType: integer = atSimpleLogin;
                          smtp_port: integer = 25;
                          email_priority: integer = 2);
var
  idmsgSend: Tidmessage;
  smtp: Tidsmtp;
  i: integer;
begin
  idmsgSend := Tidmessage.Create(nil);
  smtp := Tidsmtp.Create(nil);
  try
    with IdMsgSend do
    begin
      Body.Assign(email_text);
      From.Text := sender_email;
      ReplyTo.EMailAddresses := sender_email;
      Recipients.EMailAddresses := recipent_email; { To: header }
      Subject := email_subject; { Subject: header }
      Priority := TIdMessagePriority(email_priority); { Message Priority }
      CCList.EMailAddresses := ''; {CC}
      BccList.EMailAddresses := ''; {BBC}
      ReceiptRecipient.Text := '';
    end;

  {attachment settings}
  if assigned(attachment_list) then
    for i := 0 to attachment_list.Count - 1 do
      TIdAttachment.Create(IdMsgSend.MessageParts, attachment_list.Strings[i]);

  {authentication settings}
  case SmtpAuthType of
    0: SMTP.AuthenticationType := atNone;
    1: SMTP.AuthenticationType := atLogin; {Simple Login}
  end;

  SMTP.Username := smtp_username;
  SMTP.Password := smtp_password;

  {General setup}
  SMTP.Host := smtp_host;
  SMTP.Port := smtp_port;

  {now we send the message}
  SMTP.Connect;
  try
    SMTP.Send(IdMsgSend);
  finally
    SMTP.Disconnect;
  end;

  finally
    idmsgSend.free;
    smtp.free;
  end;
end;
ich habe ein ausführliches Beispiel Programm angehängt
mfg smallsmoker

[edit=TBx]Da der Nutzer Cluni eine mögliche Infizierung der BeispielExe gemeldet hat, wurde diese ausgeschnitten. Mfg, TBx[/edit]
Angehängte Dateien
Dateityp: zip email_example_169.zip (2,3 KB, 59x aufgerufen)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:31 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