How to send a mail message using Indy's smtp server component?

后端 未结 2 2016
野的像风
野的像风 2021-02-20 17:09

Since the demo given in http://www.indyproject.org/Sockets/Demos/index.EN.aspx only saves the received stream to a file, I don\'t know how to effectevely send that stream as a m

2条回答
  •  无人及你
    2021-02-20 17:40

    Here's a complete example on how to send an email:

    VAR SMTP : TIdSMTP;
    VAR MSG : TIdMSG;
    .
    .
      MSG:=TIdMSG.Create(NIL);
      TRY
        WITH MSG.Recipients.Add DO BEGIN
          Name:='';
          Address:=''
        END;
        MSG.BccList.Add.Address:='';
        MSG.From.Name:='';
        MSG.From.Address:='';
        MSG.Body.Text:='';
        MSG.Subject:='';
        SMTP:=TIdSMTP.Create(NIL);
        TRY
          SMTP.Host:='x.x.x.x'; // IP Address of SMTP server
          SMTP.Port:=25; // Port address of SMTP service (usually 25)
          SMTP.Connect;
          TRY
            SMTP.Send(MSG)
          FINALLY
            SMTP.Disconnect
          END
        FINALLY
          SMTP.Free
        END
      FINALLY
        MSG.Free
      END;
    .
    .
    

    (I know that WITH is frowned upon, but I generally use it in instances like this where there's no doubt as to what is going on, and where there's no (or just an infinitesimal) chance of ambiguity)

提交回复
热议问题