Solved

Question about SMTP and Delphi

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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