?
Solved

Question about SMTP and Delphi

Posted on 2004-04-10
3
Medium Priority
?
1,245 Views
Last Modified: 2007-12-19
Hi, i have a few questions about SMTP, I am currently using NMSMTP to send email with my app but i'm having some problems,
When my program cant get a connect with a SMTP server, it gives an error
"Null remote address" on the invalid host event, i need to make that error message go away, and make it do a loop trying to get a connect by  appendding mail. or smtp. ,gate. ect.  to the target domain (that i'm sending mail to) and will that send an e-mail? can i put mx1. or something, Please Help, basically i need something to get a connect if my program cant find local smtp server.
0
Comment
Question by:herd_bone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:herd_bone
ID: 10799456
sorry about the points i'm out
0
 

Expert Comment

by:jontebgood
ID: 10800614
what smtp server adress do u use then? can u ping it?

Regards

J
0
 

Accepted Solution

by:
efryer earned 160 total points
ID: 10819775
First of all, may I recommend that you look at

http://www.indyproject.org/index.html

The product is free for use (including commercial applications) as long as you credit them somewhere in the application (splash screen etc).
The product is reasonably stable, was included as part of Delphi 7 that I use, and I do use it in commercial applications.
Is available for Delphi 5 - 8.

With NMSMTP, whilst my memory is a bit hazy, I was not happy with it, and many others have expressed similar views (mainly timing issues).

I have included working code using the Indy components. You can use it with the Indy tools if you decide to install them, or just to review and correlate back to the requirements of the library that you wish to use.

///////////////////// CODE using Delphi 7 and Indy Components ////////////////////////////

Procedure ????????????????????????? //usually from an event like a button click

begin
   // the main variables that you will modify for each message
    messagememo.lines.add('your message text');
    messagememo.lines.add('more text if you need it');
    emailaddress := 'johnsmith@somedomain.com');

// standard message variables required
with Idmessage1 do
      begin
         Body.Assign(messagememo.Lines);
         From.Text := 'yourname@yourdomain.com';
         ReplyTo.EMailAddresses := 'yourname@yourdomain.com';
         Recipients.EMailAddresses := emailaddress; { To: header }
         Subject := 'Subject of the message goes here'; { Subject: header }
  //       Priority := TIdMessagePriority(cboPriority.ItemIndex); { Message Priority }
         CCList.EMailAddresses := ''; {CC}
         BccList.EMailAddresses := ''; {BBC}
         ReceiptRecipient.Text := '';
      end;

//smtp authentication - first two lines.....smtp standard requirements - next two lines
idSMTP1.Username := 'yourmailloginname'; //usually your pop3 mail login
idSMTP1.Password := 'yourmailloginpassword'; //usually your pop3 password
idSMTP1.Host := 'mail.yourdomain.com'; // if you are with an ISP, normally mail.ISPDomain.com (e.g. mail.earthlink.com)
idSMTP1.Port := 25;
{now we send the message}
idSMTP1.Connect;
try
  idSMTP1.Send(IdMessage1);
finally
  idSMTP1.Disconnect;
end;
application.terminate;
end;

That is about as simple as an smtp sending app as you can get. You can put more code in to trap errors, but for this purpose, lets keep it simple.
Just make sure that you have the idMESSAGE (indy misc) and idSMTP (indy clients)  components on the form.

One of the things that may be causing you an issue, is that some ISP's have protection (from spam, relaying etc), that requires you actually access the pop server first, before they let you send (most mail clients do it this way round normally). The way around this, is providing authentication to the SMTP server (usually your normal mail login and password), and this does not require you to perform a pop3 receive first.

As you can see in the code, I have setup SMTP authentication, and there is no harm in always adding this anyhow.

I hope this helps a little.....

Regards

Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question