indy10으로 163으로 메일을 보내는 예

1277 단어 메일을 보내다
function TForm1.SendMail(Const SMTPServer: String; Const SMTPPort: WORD;
           Const UserName, PassWord, MailTitle: String; Const MailBody: TStrings;
           Const FormAddress, ToAddress: String): Boolean;
var
  IdSMTP: TIdSMTP;
  IdMessage: TIdMessage;
begin
  IdSMTP := TIdSMTP.Create;
  IdMessage := TIdMessage.Create;
  try
    try
      IdSMTP.Host     := SMTPServer;
      IdSMTP.Port     := SMTPPort;
      IdSMTP.Username := UserName;
      IdSMTP.Password := PassWord;
      IdSMTP.Connect;
    except
      Result := False;
      Exit;
    end;
    IdMessage.Subject := MailTitle;
    IdMessage.Body.Text := MailBody.Text;
    IdMessage.From.Address := FormAddress;
    IdMessage.Recipients.EMailAddresses := ToAddress;
    try
      IdSMTP.Send(IdMessage);
      Result := True;
    except
      Result := False;
    end;
  finally
    IdSMTP.Free;
    IdMessage.Free;
  end;
end;

 
호출은 다음과 같습니다.
procedure TForm1.Button1Click(Sender: TObject);
begin
  if SendMail(Edit3.Text, StrToInt(Edit4.Text), Edit1.Text, Edit2.Text, Edit5.Text, Memo1.Lines, Edit6.Text, Edit7.Text) then
    MessageLabel.Caption := ' '
  else
    MessageLabel.Caption := ' ';
end;

좋은 웹페이지 즐겨찾기