Link to home
Start Free TrialLog in
Avatar of Balshe
Balshe

asked on

Using IdSMTPServer ?

Hi,

My question is : how can i use IdSMTPServer to send e-mails from my PC? or is there is a way to send bulk e-mails without using My ISP, Hotmail, Yahoo, or google accounts? and if i must use one of those then how can i do it?

knowing i have Delphi 2006, INDY 10 components.

also please note that i don't want to buy any component, if there is a free components Plus Examples on how to use them in the way that I've just mentioned, then it's also a good idea, but i prefer if it's INDY 10 and IdSMTPServer.

thanks in advance,
ASKER CERTIFIED SOLUTION
Avatar of AndersonCarli
AndersonCarli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Balshe
Balshe

ASKER

i've already tryied those, but it didn't work
when i use "Indy 10 SMTPServer" demo i get this error"socket error # 10048 address already in use" and i didn't know how to fix it

do you have another example?


regards,
Avatar of Wim ten Brink
You said: is there is a way to send bulk e-mails without using My ISP, Hotmail, Yahoo, or google accounts

is there is a way to send bulk e-mails without using My ISP, Hotmail, Yahoo, or google accounts?

Anyone who is asking "is there is a way to send bulk e-mails without using My ISP, Hotmail, Yahoo, or google accounts" is trying to build a spambot, if you ask me. :-(
I have to agree to Alex' thought.

So maybe Balshe will give some more information about what he wants to.

The Answer to you #10048 is simple, but I won't help anyone building a spambot.
Avatar of Balshe

ASKER

guys you got me wrong :)

i want to create a monitoring tool for my PC at home and at work but i don't want anyone to know about it, and i don't want it to use any if my accounts or the company account because it's monitored. also it's some times needed to test our new outlook exchange projects in the company and I've been asked many times to build a program to send bulk e-mails to a specific account in the company or to multiple accounts to see how the anti spam procedure and program is working.
beside i've done it before in VB, but i don't know how to do it in Delphi.
so any suggestions?


Regards,
Avatar of Balshe

ASKER

I found this on INDY Docs.

//--
For TIdLPR and TIdRSH, we force the client to bind to a local port within a specific range before connecting to a server because these protocols require the client to use specific local port ranges when making a connection to a server.  This is done with the TIdTCPClient.BoundPortMin and TIdTCPClient.BoundPortMax properties.

 

Usually, if you do this with a specific IP address while a local port is in FD_WAIT state, the bind fails and Indy will then try to bind to the next port.  Unfortunately, when using the wildcard IP address (0.0.0.0), the bind will succeed while a port is in a FD_WAIT state but when you connect, you get an "Address already in use" error.  

 

The only workarounds available are:

 

• Wait a minute for the local port to get out of FD_WAIT state.

• Set the TIdTCPClient.BoundIP property to the to the machine's current local IP address.  This workaround can be problematic if a machine has more than one local IP address and you do not know which one to use.

 

For most clients, the best practice is to let the stack select any available local port because most servers do not care what local port the client is using and because of the issue we mentioned earlier.  Do not use the TIdTCPClient.BoundPort, TIdTCPClient.BoundPortMax, and TIdTCPClient.BoundPortMax properties unless you have a very compelling reason to do so.



//----

so now i put  TIdTCPClient.BoundIP =my local ip address
and i put the IDSMTP.BINDING to (0.0.0.0:158) PCMail-srv.

now i think it will work, i'll keep u updated guys

regards,

Avatar of Balshe

ASKER

ok Guys,

i reached a point where the SmtServer receives the message, but how can i make the smtp server sends the message to required e-mail address ???


regards,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Balshe

ASKER

Though i said i  said i don't want to send the email  using my ISP account Nor Gmail, but it's possible to use Gmail account, but the problem with Gmail is that i get an error message "Exception class EIdTLSClientSSLIOHandlerRequred with message 'SSL IOHandler is required for this setting"

Here is the code:




procedure TForm1.IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext;
  AMsg: TStream; var LAction: TIdDataReply);
var
 LMsg : TIdMessage;
 LStream : TFileStream;
 SMTP :TIdSMTP;
 MailHStack : TIdIOHandlerStack ;
begin

      LStream := TFileStream.Create(ExtractFilePath(Application.exename) + 'test.eml', fmCreate);
      MailHStack := TIdIOHandlerStack.Create(nil);
      SMTP := TIdSMTP.Create(nil);
      SMTP.AuthType := atSASL;
      SMTP.IOHandler := MailHStack;
      SMTP.UseTLS :=utUseImplicitTLS   ;
      SMTP.UseEhlo := True;
      SMTP.Host := 'smtp.gmail.com';
      SMTP.Port := 587;
      SMTP.Username:='MYGMAILACC@gmail.com';
      SMTP.Password:='MYPASS';
      LMsg:=TIdMessage.Create(nil);
      LMsg.LoadFromStream(LStream);
      SMTP.Connect();
      SMTP.Send(LMsg);
      if(SMTP.Connected) then SMTP.Disconnect;
      SMTP.Free;
Try
 LStream.CopyFrom(AMsg, 0);
Finally
 FreeAndNil(LStream);
End;

LMsg := TIdMessage.Create;
Try
 LMsg.LoadFromFile(ExtractFilePath(Application.exename) + 'test.eml', False);
 ToLabel.Caption := LMsg.Recipients.EMailAddresses;
 FromLabel.Caption := LMsg.From.Text;
 SubjectLabel.Caption := LMsg.Subject;
 Memo1.Lines := LMsg.Body;
Finally
 FreeAndNil(LMsg);
End;

end;



all this is because Gmail Needs to receive STARTTLS command first
since i got this error:"Must issue a STARTTLS command first"
and if you go to this link:
http://www.indyproject.org/KB/index.html?smtpmuststarttls.htm
you will find the solution:
"Indy 10 supports SMTP with explicit TLS.  In the Indy 10's TIdSMTP, you simply have to assign a TIdSSLIOHandlerSocketBase descendent to the TIdSMTP.IOHandler property and set the UseTLS property to either utUseRequireTLS if you do not want to use an unencrypted connection or utUseExplicitTLS if you are willing to use an unencrypted connection."

but i didn't know how to do it
can you help me here?
Balshe,

because I still use Indy9, my knowledge regarding the Indy10 SSL components is limited. I use the 'Clever Internet Suite' for doing ssmtp, which is quite nice and stable (no, I'm not connected to this company ;)).

But as far as I understand you just need to do this:

SMTP.IOHandler := <your TIdSSLIOHandlerSocketBase descendent>;
SMTP.UseTLS :=utUseExplicitTLS; //or utUseRequireTLS

But maybe one of the other peoples here has an exact information on this.

gracias
icecoke
Avatar of Balshe

ASKER


thanks "real_icecoke" for your answer,

but i need to know how to use "IOHandler " along with "TIdSSLIOHandlerSocketBase descendent"

"Workshop_Alex" what do you think ? :)

Regards,
hmm - thought this could be done by a simple:

mySIOH := TIdSSLIOHandlerSocketBase.Create;
SMTP.IOHandler := mySIOH;

but as I said - I have no indy 10.

So, listening.......



icecoke
> "Workshop_Alex" what do you think ? :)

I still think your intentions are a bit suspicious. You want to create a bulk emailer which bypasses your ISP at home and at work, making sure no one can link it back to you. If it's just for a simple monitoring tool then I just wonder why you're not using other techniques for this purpose. If all you want to do is monitor some system then it seems to me that a technique like SOAP would be far less suspicious.

The problem with GMail is the SSL for which the Indy components require some additional DLL. This DLL isn't freely available all over this world, even if it's a free tool. The techniques it contains cannot be exported to certain countries due to the laws on encryption in the USA. But I think that a Google search might turn up some sample code for Delphi/Indy that will allow you to send emails through the Google servers. At home I even have some code that allows me to send emails through SMTP over Google but right now (and for the next 8 hours) I'm not at home. Is that what you're looking for?
Avatar of Balshe

ASKER

Guys thanks for your support,

Dear Workshop_Alex,
if i'm going to use Gmail, do u think it's suspicious ?. anyway it's not for bad purpose i assure you. and it would be great if you send me some code that explains how to send through Gmail SMTP servers.
Also i would like for my program to be stand-alone not using additinal DLLS, is it possible ?

thanks again guys
Nope. Using GMail wouldn't be suspicious in my opinion. GMail is taking actions against spammers and people who abuse their email system. Btw, I am willing to believe you but can't take the risk that you're dishonest in your intentions. We don't need any more spammers. :-)

You still have to wait about 4 more hours before I'm back home, where I have some sample code available for sending emails with GMail. (And also on how to receive them from a GMail POP3 setup.) Unfortunately, I am not aware of any solution without the use of this special SSL DLL.
Avatar of Balshe

ASKER



i reached a point where i need a dll file "ssleay32.dll"
and i found it but it seems to be the wrong version, and i don't know if i need this dll "libeay32.dll" or not

and now i'm getting error "can not load SSL Library"


and here is the code




procedure TForm1.IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext;
  AMsg: TStream; var LAction: TIdDataReply);
var
 LMsg : TIdMessage;
 LStream : TFileStream;
 SMTP :TIdSMTP;
 SSL_LIST:TIdSASLEntries ;
 SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin

      LStream := TFileStream.Create(ExtractFilePath(Application.exename) + 'test.eml', fmCreate);

      SSL_LIST:=TIdSASLEntries.Create(nil);
      SSLHandler:=TIdSSLIOHandlerSocketOpenSSL.Create;
      SSLHandler.Destination := 'SMTP.gmail.com:465';
      SSLHandler.Host := 'SMTP.gmail.com';
      SSLHandler.Port := 465;
      SSLHandler.DefaultPort := 0;
      SSLHandler.SSLOptions.Method := sslvTLSv1;
      SSLHandler.SSLOptions.Mode := sslmUnassigned;
      SSLHandler.SSLOptions.VerifyMode := [];
      SSLHandler.SSLOptions.VerifyDepth := 0;
      SMTP := TIdSMTP.Create(nil);
      SMTP.IOHandler := SSLHandler ;
      SMTP.UseTLS :=utUseImplicitTLS   ;
      SMTP.UseEhlo := True;
      SMTP.Host := 'smtp.gmail.com';
      SMTP.Port := 465;
      SMTP.Username:='MyGmailAcc@gmail.com';
      SMTP.Password:='MyPass';
      LMsg:=TIdMessage.Create(nil);
      LMsg.LoadFromStream(LStream);
      SMTP.Authenticate;
      SMTP.Connect();
      SMTP.Send(LMsg);
      if(SMTP.Connected) then SMTP.Disconnect;
      SMTP.Free;


Try
 LStream.CopyFrom(AMsg, 0);
Finally
 FreeAndNil(LStream);
End;

LMsg := TIdMessage.Create;
Try
 LMsg.LoadFromFile(ExtractFilePath(Application.exename) + 'test.eml', False);
 ToLabel.Caption := LMsg.Recipients.EMailAddresses;
 FromLabel.Caption := LMsg.From.Text;
 SubjectLabel.Caption := LMsg.Subject;
 Memo1.Lines := LMsg.Body;
Finally
 FreeAndNil(LMsg);
End;

end;

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Balshe

ASKER

Dear Workshop_Alex,


What is : idSMTPStatus, idSMTPDisconnected, idSMTPWork, idSMTPWorkBegin, idSMTPWorkEnd, idSMTPFailedRecipient, and idSMTPTLSNotAvailable  ?

Regards,
Oh, I forgot about those. Those are events. :-) No need to use them but I used them to generate all kinds of status information.

    procedure idSMTPDisconnected( Sender: TObject );
    procedure idSMTPFailedRecipient( Sender: TObject; const AAddress, ACode, AText: string; var VContinue: Boolean );
    procedure idSMTPStatus( ASender: TObject; const AStatus: TIdStatus; const AStatusText: string );
    procedure idSMTPTLSNotAvailable( Asender: TObject; var VContinue: Boolean );
    procedure idSMTPWork( ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer );
    procedure idSMTPWorkBegin( ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Integer );
    procedure idSMTPWorkEnd( ASender: TObject; AWorkMode: TWorkMode );
    procedure IdSSLIOHandlerSocketOpenSSLGetPassword( var Password: string );
    procedure IdSSLIOHandlerSocketOpenSSLStatus( ASender: TObject; const AStatus: TIdStatus; const AStatusText: string );
    procedure IdSSLIOHandlerSocketOpenSSLStatusInfo( Msg: string );

All these events do is add some line to my log file, keeping a close eye on the whole status.

You don't need them! But they are useful in displaying the progress...
Avatar of Balshe

ASKER

Still Getting this error "Could not load SSL Library"
Avatar of Balshe

ASKER

i got the correct DLLs at http://indy.fulgan.com/SSL/indy_OpenSSL096m.zip
but now i get this : "Connection Closed Gracefully" from the client Side, while from the server side it seems as if it's sent, while there is no message received to the address required.



What do you think?


why is it much easier in VB ?? O.M.G





Avatar of Balshe

ASKER

now it worked,(Thanks to Workshop_Alex, and real_icecoke and all of you guys) , but i have to install those dlls on the PC's that i want this tool to work on ??

isn't there a better way, another way without using those Dlls?








Balshe,

I use 'Clever Internet Suite' and 'ip*works' instead of indy10 for ssmtp/pops - no use for additional DLLs and easy to implement. But both are commercial.

icecoke
@Blashe,
The separate DLLs are required because they contain the encryption technology which is required for the secure connection that GMail wants. And basically all you have to do is put these DLLs in the same folder as your executable. No need to register them or set them up in some way.
Unfortunately, those same DLLs have an export restriction mandated by the US laws. Makes it a bit difficult to export your application to North Korea... :-) But it also means that the sourcecode for these DLLs is also a bit difficult to get.

real_icecoke might have a good alternative, though. Unfortunately, I am unfamiliar with both component sets. 'Clever Internet Suite' looks very interesting though, but quite expensive. It amazes me that they don't seem to mention the export restriction on SSL encryption, though.

(The SSL DLLs can be downloaded from http://adg.bmpcoe.org/IndySSL/ in case you need them. But apparantly you already have them.)

Read: http://www.indyproject.org/KB/index.html?wherecanidownloadindysss.htm for a little bit more about the export restriction. Also read http://en.wikipedia.org/wiki/Ssl for more information. And finally, there might be an alternative solution for Delphi that uses Indy but not these separate DLLs but I don't know them. (Not yet, that is.)
http://www.openssl.org/ is also a nice read. :-)
Avatar of Balshe

ASKER

thank you all for answering , but what about SMPT RELAY ?
when i read the documentation about SMTP Relay i found that it's possible to send e-mail from ur machine and that the smtp relay component will look for DNS/IP, but i couldn't implement it. also couldn't make the demo provided with IND 10 to work without writing a valid DNS, and didn't know what should i write in the DNS field. it said on the INDY web site that if you don't write a DNS the component shall make a DNS Lookup ...!! but it's not working also.

thanks all for your replies, but i think we are all trying to learn something new here, and we all are looking for a way to send e-mail from stand-alone machine. i really like the challenge, and i like to read about Programming related stuff, but I'm facing great walls regarding this subject.



regards,

http://en.wikipedia.org/wiki/SMTP_relay for SMTP Relays. :-)

Anyway, open relays are likely to be blacklisted and this stopped by your spamfilter or even your ISP. Most SMTP servers will therefore close their doors except for those connections they trust. If you find one, chances are that it will be blacklisted and possibly your ISP will block any email from that server to your system.
http://www.marcocantu.com/tips/oct06_gmail.html

Apparantly he doesn't seem to need those DLLs or maybe he forgot to mention them. :-)
Avatar of Balshe

ASKER

sorry guys, but i need more time to check the answers and try a few things.

thanks for your help.
Forced accept.

Computer101
EE Admin
Avatar of Balshe

ASKER

None of the apove seems to be the asnwer i need !!
WorkshopAlex:
Are you willing to share your code for these events and how you act on them during the process of sending?

    procedure idSMTPDisconnected( Sender: TObject );
    procedure idSMTPFailedRecipient( Sender: TObject; const AAddress, ACode, AText: string; var VContinue: Boolean );
    procedure idSMTPStatus( ASender: TObject; const AStatus: TIdStatus; const AStatusText: string );
    procedure idSMTPTLSNotAvailable( Asender: TObject; var VContinue: Boolean );
    procedure idSMTPWork( ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer );
    procedure idSMTPWorkBegin( ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Integer );
    procedure idSMTPWorkEnd( ASender: TObject; AWorkMode: TWorkMode );
    procedure IdSSLIOHandlerSocketOpenSSLGetPassword( var Password: string );
    procedure IdSSLIOHandlerSocketOpenSSLStatus( ASender: TObject; const AStatus: TIdStatus; const AStatusText: string );
    procedure IdSSLIOHandlerSocketOpenSSLStatusInfo( Msg: string );
Avatar of Balshe

ASKER

wow this is a 5 years old question, i forgot all about this, i remember i didn't complete this one, sorry :)