Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 10-08-2016, 11:55 PM
tcsh tcsh is offline
Member
 
Join Date: Sep 2016
Posts: 37
Question Send email from TDBGrid

The thread title might be a bit weird but hopefully you'll get it once I explain further here.

I got a TDBgrid in my software that lists 11 columns containing various information like client name, email, phone number, price (of his order), and so forth..

I'd figure I'd select a particular row (thus a particular order and it's details) right click it, click a popupmenu item which would in turn send an email to the client.

For the address to send the email to it would pull the email address contained in the email column for that row I selected.

For the subject it would write something predefined like "Your order is ready"
For the message body it would be something predefined + data from some of the columns, something like:

Hello, [name, from name column]

Your order is confirmed.

Here are your details:

Price: [actual price, from price column]
Order details: [actual details, from details column]

Thank you

That's about it.

Now, reading a bit on google about this I've come across some resources that mention Indy and 2 of it's components, namely:

TIdSMTP
&
TIdMessage

I did find various ready made software using these but they all use TEDit's and so on to input the data manually, I'd like it to be pulled from the above mentioned and just send. I'd use the SMTP from my hosting provider that hosts my website, for the actual mail sending part.

Anyone has any experience and is willing to spend a few hours helping me out to implement this, if it's possible? Or providing some help here in the topic as I try implementing it..

I'm having a tough time doing this alone since I'm way too new at delphi.

Appreciate it, thanks.
Please do let me know if something is unclear or if you need any more info.
  #2  
Old 10-09-2016, 12:58 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

See the below link:

http://delphi.about.com/od/indy/a/email-send-indy.htm


In your case it should be something like this:


Code:
IdSMTP1.Host := 'Put the host name here';
IdSMTP1.Port := 25;

//setup mail message
MailMessage.From.Address := 'Abdulaziz Jasser';
MailMessage.Recipients.EMailAddresses := DBGrid1.DataSource.DataSet['TheFieldThehastheEmailAddress'];
MailMessage.Subject   := 'Your order is ready';
MailMessage.Body.Text := 'This is the body' + DBGrid1.DataSource.DataSet['MoreDataFromthe Columns'];

//send mail   try
IdSMTP1.Connect;
IdSMTP1.Send(MailMessage);
IdSMTP1.Disconnect;
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 10-09-2016 at 01:24 PM.
  #3  
Old 10-09-2016, 02:06 PM
tcsh tcsh is offline
Member
 
Join Date: Sep 2016
Posts: 37
Default

Quote:
Originally Posted by Jasser View Post
See the below link:

http://delphi.about.com/od/indy/a/email-send-indy.htm


In your case it should be something like this:


Code:
IdSMTP1.Host := 'Put the host name here';
IdSMTP1.Port := 25;

//setup mail message
MailMessage.From.Address := 'Abdulaziz Jasser';
MailMessage.Recipients.EMailAddresses := DBGrid1.DataSource.DataSet['TheFieldThehastheEmailAddress'];
MailMessage.Subject   := 'Your order is ready';
MailMessage.Body.Text := 'This is the body' + DBGrid1.DataSource.DataSet['MoreDataFromthe Columns'];

//send mail   try
IdSMTP1.Connect;
IdSMTP1.Send(MailMessage);
IdSMTP1.Disconnect;
Hello, thanks for your reply.

That's actually the link I found and the source I looked over, unfortunately it got me very confused because of all the TEdit's, inputting manually and attachment. Things I don't need.

Your examples does make a bit of sense, I'll run through what I'm doing if you don't mind guiding me.

I've just opened my project, added a new action to my TActionManager and named it
Code:
actSendMail
I've then went on to my PopUpActionBar and added the new action.

Ok, now when I right click the row I selected in DBGrid at runtime the popup displays that new action / button - named Send Mail.

I presume your code example would need to be added to my new action, on execute, right?

If yes, this is what I did:

I double clicked the new action in the ActionManager, this sent me to the code editing, it now looks like this:

Code:
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've also added TIdSMTP and TIdMessage to my form and changed your code accordingly:

from MailMessage to IdMessage1.

I've tried sending and I'm getting an error, I've detailed things about the error here if you can have a look pls:

http://stackoverflow.com/questions/3...and-tidmessage

Any thoughts?
Thank you!

Last edited by tcsh; 10-09-2016 at 10:43 PM.
  #4  
Old 10-10-2016, 08:17 PM
tcsh tcsh is offline
Member
 
Join Date: Sep 2016
Posts: 37
Default

Solved. The problem was a missing IOHandler and some ssl drivers, you can read all the details here:

http://stackoverflow.com/questions/3...and-tidmessage

Check the accepted answer + it's comments.

Works like a charm, thank you for the help Jasser.
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:00 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.