Solved

Question about SMTP and Delphi

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

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