Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending e-mail when condition met 2

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
I was just asked to make an application send someone an e-mail when a certain set of entries are made in a database. I already have a the program made...I just need to know how to send an e-mail to a certain person. I'm sure I'll have more questions, but I need to get started.

Thanks a lot for stopping by!
 
The Indy components provide an easy way to send emails.

This is what you do:

Drop a TIdSMTP component and a TIdMessage component on your form.

Using the object inspector (or at run time), set up the Host, password and username properties of the TIdSMTP component.

Using the object inspector (or at run time), set up the From properties (Address, Name, Text), Subject.

Using the object inspector (or at run time), set up the Body and Recipients property of the TIdMessage component.

Assuming that your TIdSMTP component is named Mail and your TIdMessage component is named MailMessage then the code to actually send your email should be something like:
Code:
  Mail.Connect;
  ...
  Mail.Send( MailMessage );
  ...
  Mail.Disconnect;
It would be good practice not to hard code the password either at design or run time. The actual text of the email message and the recipient(s) is also likely to be created at run time using information from your database.

I found that using these components was straightforward. The hardest part was locating the components on the Component palette - there are lots of them.

Andrew
Hampshire, UK
 
Wow, thank you all very much. Towerbase, I had already got the previous example working before I saw your post...but it DOES look easier, I may try it in the future, thank you.

Now, in the code provided on the FAQ, it opens up my default mail client. We use Netscape mail here(I know, I know), and it works fine...except it brings up Netscape maile AND browser when I click the button. Any ideas as to how to maybe stop that from happening.

Also, I made an attempt at your suggestiong, towerbase, but the only SMTP component I could find was an SMTPServer and it didn't have the fields that you mention. Am I looking at the wrong thing?
 
Well, ok. I think I figured your way out...somewhat, towerbase. I found the component you were talking about, and I think I filled everything out correctly. Now, when I click on the button I can see some activity on my network connection...but nothing really happens. I haven't gotten any messages or anything.

I decided to try this way, since having Netscape open up every time was just getting on my nerves...and this really does seem simple...I just can't get it to work. Sorry for being a pest about this.
 
Remember that if you've set your SMTP Server to be an internal mail server (like Exchange), and the target e-mail address is external to the server, then the server will reject it if anti-relay settings have been set up (which they should be). This is something I ran up against.

If that's the case, then set the SMTP Server property to be the ISP's SMTP gateway server.
 
Griffyn,

normally you can specify in Exchange (or whatever smtp server) which Ip adresses that are allowed to do relaying...

--------------------------------------
What You See Is What You Get
 
Jnah86, when you say you can't get it to work, does it actually send an email? You won't see anything on the screen because these are non visual components. These Indy components don't use your email client to send the emails. They just send them to your ISP or whatever using SMTP.



Andrew
Hampshire, UK
 
As far as I can tell it's not sending it. I'm having it send to a local address, and I'm getting nothing. I don't get any errors either, though. I'm using the server name, but I've also tried the IP, not sure which would be better. Like I said, when I click the button I can see the lights turn on on the network connection...so SOMETHING must be happening, I'm just not sure what.
 
Have you tried sending the email to an external email address such as your own personal one? If so, did it work?

Andrew
Hampshire, UK
 
Here's a funny thing. I made a new application today just to mess with this, and it works perfectly. Now in my other application it still won't work at all. I sent to an outside and internal address on the new app...but nothing seems to work on the old one. Is there anything I could be doing in the app that would make it not compatible with this method?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top