Home Sending email using TIdSMTP and TIdMessage
Reply: 0

Sending email using TIdSMTP and TIdMessage

user2050
1#
user2050 Published in June 25, 2018, 3:56 am

I'm using an action from my ActionManager to send an email to a client in my DBGrid.

I select the row with the client details in my DBGrid, right click, a Popupactionbar comes up, I click the send mail action and the mail should be sending.

This is the code for the mail send action:

procedure TForm2.actSendEmailExecute(Sender: TObject);
begin
IdSMTP1.Host := 'smtp.mail.yahoo.com';
IdSMTP1.Port := 465;

//setup mail message
IdMessage1.From.Address := 'my email address is here';
IdMessage1.Recipients.EMailAddresses := DBGrid1.DataSource.DataSet['email'];
IdMessage1.Subject   := 'test subject';
IdMessage1.Body.Text := 'test email body' + DBGrid1.DataSource.DataSet['details'];

//send mail try
IdSMTP1.Connect ;
IdSMTP1.Send(IdMessage1) ;
IdSMTP1.Disconnect;
end;

I'm using TIdSMTP and TIdMessage (Indy components). I've also set the hostname, port, username and password in the TIdSMTP Properties using Object Inspector, all details are as yahoo provided them on their website (hostname, port, my email for login and my email password)

In the row I select in DBGrid there is a field named email which contains the mail address of the client, hence that is where the email should go. Also, I'm adding some information contained in a field named details, which should go in the body section of the email (see above code)

Once I start my software up, select the row in DBGrid and hit send on the action button, the software freezes (not responding) for somewhere around 20-40 seconds than it returns an error saying: Connection closed gracefully.

I'm using yahoo smtp just to test things out, I would eventually be using the smtp from my hosting provider that hosts my website (and where the db is located also)

Indy version 10.6.2.5311 Using Delphi 10 Seattle

Any thoughts as to what I'm doing wrong so far?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32954 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO