Solved

Question about SMTP and Delphi

Posted on 2004-04-10
3
1,236 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
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 80 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now