Delphi/Send email using Delphi code
I'm studying Delphi and I'm trying to make this example work, it's taken from "Teach Yourself Delphi 4 in 21 Days"
For the host I tried smtp.gmail.com, I also tried port
465, I tried imtp... the program connects to the server, but when I execute the code to send an email a messagedlg box pops up saying "incomplete header". I tried it in Delphi 4 as well as in 7, I can't find the way of making this work, it's very tiring going through a book and speding months trying things that never work...
Could you please help me out? I include the code I'm trying below. I also have installed Delphi 2010 if you wish to provide examples for 2010 version.
SMTP.Host := `mail';
procedure TMainForm.SMTPConnect(Sender: TObject);
with SMTP.PostMessage do begin
FromAddress := `';
Subject := `Test';
Body.Add(`This is a test');
I don't have a lot of experience with smtp, but I know that if you leave the From and To fields blank as in the code above, the mail server (and possibly even Delphi) will reject the message. You've got to put in an email address in both of those, and SMTP.Host needs to be pointing at a live SMTP server instead of 'mail'. The best test is to use your own email address given to you by your ISP, and then email yourself as a test, since the ISP should give you a valid server address that matches your email account.