Einzelnen Beitrag anzeigen

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