Solved

Question about SMTP and Delphi

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
Delphi Form ownership 4 73
Open a URL with Internet Explorer in a new tab (not a new window) 1 74
SUM 2 INTEGER ARRAYS INTO 1 10 93
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

861 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

25 Experts available now in Live!

Get 1:1 Help Now