Jump to content

Confirmation gmail from Remote Area


SergioFeitoza

Recommended Posts

Hi friends   

I deployed my code and is working well in my home localhost and also in the Windows Remote Area where I deployed with IIS It uses a data base MySql

I did a login system which requests e-mail confirmation when registering. The classical Indy code is below.

Someone which is registering clicks the button REGISTER and an e-mail is sent asking for clicking the token for e-mail confirmation. It works nice in the localhost. The user clicks the confirmation e-mail and the program becomes accessible (mainmodule.before login).

MY PROBLEM: When I put the dll in the remote area and access it I arrive properly to the  login page. When I click the REGISTER button I see the message “ Email was sent … click the link to confirm” and do not receive any error message . However the e-mail do not arrive  in the box – to br clicked

Is it necessary to do any adjustment in the code bellow? For example something like

    IdSMTP.Host := ' 158.XX.YY.ZZ/smtp.gmail.com';

Thanks in advance

---------------------------------------------------------- 

function TEmail.Send: boolean;                     // Indy

var

  IdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL;

  IdSMTP: TIdSMTP;

  IdMessage: TIdMessage;

 begin

  IdSSLIOHandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(Nil);

  IdSMTP := TIdSMTP.Create(Nil);

  IdMessage := TIdMessage.Create(Nil);

  try

    IdSSLIOHandlerSocket.SSLOptions.Method := sslvSSLv23;

    IdSSLIOHandlerSocket.SSLOptions.Mode := sslmClient;

    IdSSLIOHandlerSocket.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];

    IdSMTP.IOHandler := IdSSLIOHandlerSocket;

    IdSMTP.UseTLS := utUseImplicitTLS;

    IdSMTP.AuthType := satDefault;

    // Using gmail Server (do not modify this)

    IdSMTP.Host := 'smtp.gmail.com';

    IdSMTP.Port := 465;

    IdSMTP.Username        :='myEmail@gmail.com';   //   (1)

    IdSMTP.Password        :='xxxxxxxxxxxxx';

    // From

    IdMessage.From.Address :='MyEmail@gmail.com';  

    IdMessage.From.Name := 'From Me';

   IdMessage.Recipients.Add.Text := fToEmailAdresse;

    IdMessage.Subject := fObject;

    IdMessage.ContentTransferEncoding := '8bit';

    IdMessage.ContentType := 'text/plain';

    IdMessage.CharSet := 'UTF-8';

    IdMessage.Body.Clear;

    IdMessage.Body.Text:=fMessage;

    ferror:=False;

    fmes:='E-mail sent succesfully.';

    try

      IdSMTP.Connect;

      IdSMTP.Authenticate;

    except

      on E: Exception do

      begin

        ferror:=True;

        fmes:=E.Message;

      end;

    end;

    if not ferror then

    begin

      try

        IdSMTP.Send(IdMessage);

      except

        On E: Exception do

        begin

          ferror:=True;

          fmes:=E.Message;

        end;

      end;

    end;

  finally

    IdSMTP.Disconnect;

    UnLoadOpenSSLLibrary;

    FreeAndNil(IdMessage);

    FreeAndNil(IdSSLIOHandlerSocket);

    FreeAndNil(IdSMTP);

  end;

  result:=not ferror;

end;

 

Link to comment
Share on other sites

10 hours ago, SergioFeitoza said:

' 158.XX.YY.ZZ/smtp.gmail.com';

I think it is not needed.

Maybe there is a problem with server settings.  

Maybe it is a problem with UnLoadOpenSSLLibrary.

I think is not loading the SSL libraries, try to copy 32bit ssl libraries to Sys64 on system directories

Link to comment
Share on other sites

Many many years ago some Email Servers required that the sender identify themselves in the eMail Headers (old code attached):-

        IDstr:= IntToStr(Random(999))+IntToStr(Random(999))+FloatToStr(Time)+IntToStr(Random(999))+IntToStr(Random(999))+'@MyApp.users';

        ...

        IdMessage1.AddHeader('Mime-Version: 1.0');
        IdMessage1.AddHeader('Return-Path: '+EmailFrom);
        IdMessage1.AddHeader('X-Originating-Email: ['+EmailFrom+']');
        IdMessage1.AddHeader('X-Sender: '+EmailFrom);
        IdMessage1.AddHeader('X-Originating-IP: ['+IdSMTP1.Socket.Binding.IP+']');
        IdMessage1.AddHeader('Message-ID: <'+IDstr+'>');
      
        ...

Link to comment
Share on other sites

6 hours ago, irigsoft said:

I think it is not needed.

Maybe there is a problem with server settings.  

Maybe it is a problem with UnLoadOpenSSLLibrary.

I think is not loading the SSL libraries, try to copy 32bit ssl libraries to Sys64 on system directories

 

4 hours ago, andyhill said:

Many many years ago some Email Servers required that the sender identify themselves in the eMail Headers (old code attached):-

        IDstr:= IntToStr(Random(999))+IntToStr(Random(999))+FloatToStr(Time)+IntToStr(Random(999))+IntToStr(Random(999))+'@MyApp.users';

        ...

        IdMessage1.AddHeader('Mime-Version: 1.0');
        IdMessage1.AddHeader('Return-Path: '+EmailFrom);
        IdMessage1.AddHeader('X-Originating-Email: ['+EmailFrom+']');
        IdMessage1.AddHeader('X-Sender: '+EmailFrom);
        IdMessage1.AddHeader('X-Originating-IP: ['+IdSMTP1.Socket.Binding.IP+']');
        IdMessage1.AddHeader('Message-ID: <'+IDstr+'>');
      
        ...

Thank you very much Andyhill . I understood and will implement this also , in addition to the above. My provider Remote Area is Windows Server 2012

As I wrote in another post of yesterday I am looking for a new provider  which works better than my current one. I hope to conclude this today

Link to comment
Share on other sites

Set a memo at you interface and log the sending using the indy components...

GMail has a lot of rules to service a message via their smtp. And some those rules only come up login the sending. Rules like, less secure apps, ip geolocation security, etc etc

Link to comment
Share on other sites

41 minutes ago, Fred Montier said:

Set a memo at you interface and log the sending using the indy components...

GMail has a lot of rules to service a message via their smtp. And some those rules only come up login the sending. Rules like, less secure apps, ip geolocation security, etc etc

Thanks and Good idea I will check. Anyway I am going today or tomorrow to put my dll in a new provider and will able  to see if works there. The fact is that in my localHost everything works perfectly. In the Remote Area of the provider only the Email is not been receiving (although no error message)

Unfortunately, the REMOTE AREA is not working for doing the test. Something tells me that in a better provider it will work as well as in my localhost

Link to comment
Share on other sites

Hi,

Personally, I am not a fan of sending email via gmail, hotmail etc. As Fred also points out, there are many rules that you have to take into account.
Rules that change often and that you often cannot set yourself. You also often have to take into account the relationship between an e-mail address
and the domain from which you send it.

Be aware that when you send a lot of mail VIA gmail (bulk mail), you will soon be blocked because of spam.
Much is then a relative concept because mail is monitored on the ip address / domain from which it is sent,
number per minute, hour, etc., sender and replay address, etc.

A number of guidelines apply to (bulk) mail:
- link to domains, not IP addresses in email html body.
- do not include JavaScript in email html body.
- do not include embedded Object (ActiveX / Flash) in email html body.
- don't include HTML forms in email html body.

Providers such as hotmail, gmail, yahoo impose many restrictions on sending e-mail. You do not have this when you send mail
from your own domain or take one of the options from my previous message

Some guidelines
https://support.google.com/mail/answer/81126
https://support.google.com/mail/thread/9912589?hl=en
https://help.yahoo.com/kb/emails-arent-received-yahoo-mail-sln28074.html

If you really want to use it for business to send mail from your application, you can better:
1. send mail from your own domain, so via the domain where your application is started/hosted
2. use an smtp / relay server
3. send mail via an account of the customer

Option 1: send from your own domain
You can then create an email address for each customer. Suppose your application domain name is "myapp.com". You have 2 customers who use your application. These are the companies:
- company-X (have their own website / mail)
- company-Z (have their own website / mail

You now create an e-mail address for every customer, namely:
- company-X@myapp.com
- company-Y@myapp.com

When the company uses the e-mail functionality within your application, they use the above e-mail address.
Mail will now be sent FROM your own domain name WITH the same domain e-mail address, namely @ myapp.com

The next step is to ensure that when a reply is given to this e-mail, it also reaches the relevant company.
After all, one answers to Company-X@myapp.com and the mail ends up in your mail environment.

You now put a forward line on the mailbox of company-X@myapp.com whereby the mail is forwarded to an email address
of the company, for example info@company-X.com.

Now the mail is forwarded to the company and the communication takes place directly between company and customer
who has replyd on that mail. Company-X must, however, submit an spf record in their web environment take from myapp.com.
This indicates that company-X trusts myapp.com when sending e-mail.

Option 2: use a relay server
This is the most reliable way of sending mail. A smtp provider has everything set up to send mail optimally, continuously adapting the changing
mail rules of eg gmail, hotmail, outlook, etc. All you have to do is create accounts per customer, etc. Examples of smtp / relay server providers
are for example (there are in every country). Mostly all relay server providers have test account to send a x-amount mails for testing,:
- https://www.sendinblue.com/
- https://www.mailchimp.com/
- https://www.serversmtp.com/
- https://sendgrid.com/
- https://www.flowmail.com

You then pay an x amount for an x number of mails to be sent per month, usually it starts at 15.000-20,000 per month.

Option 3: use mail server client
This option is also applied, but may result in mail being seen as a spam.
You ask your customer to create an email address with a password. What you actually do is use this data to log in to the mail server
of the customer and send mail via that mail server.

All 3 options have advantages and disadvantages. Sending mail from a different mail address than your domain (where your application is located)
is often seen as spam. Especially when you are going to send multiple mails to the same e-mail domain within a certain time.
This specific time is different for each provider (gmail, hotmail, outlook). 

Do not forget to include the correct header information in your mail, especially when you send mail using options 1 and 2.
Header information is important because the domain is often mentioned there and then you run the risk that app domain and
mail domain are different to be.

You also have a number of other settings such as Dkim, Dmarc, Tls that affect the security of mail.

Regards Peter

Link to comment
Share on other sites

36 minutes ago, mierlp said:

Hi,

Personally, I am not a fan of sending email via gmail, hotmail etc. As Fred also points out, there are many rules that you have to take into account.
Rules that change often and that you often cannot set yourself. You also often have to take into account the relationship between an e-mail address
and the domain from which you send it.

Be aware that when you send a lot of mail VIA gmail (bulk mail), you will soon be blocked because of spam.
Much is then a relative concept because mail is monitored on the ip address / domain from which it is sent,
number per minute, hour, etc., sender and replay address, etc.

A number of guidelines apply to (bulk) mail:
- link to domains, not IP addresses in email html body.
- do not include JavaScript in email html body.
- do not include embedded Object (ActiveX / Flash) in email html body.
- don't include HTML forms in email html body.

Providers such as hotmail, gmail, yahoo impose many restrictions on sending e-mail. You do not have this when you send mail
from your own domain or take one of the options from my previous message

Some guidelines
https://support.google.com/mail/answer/81126
https://support.google.com/mail/thread/9912589?hl=en
https://help.yahoo.com/kb/emails-arent-received-yahoo-mail-sln28074.html

If you really want to use it for business to send mail from your application, you can better:
1. send mail from your own domain, so via the domain where your application is started/hosted
2. use an smtp / relay server
3. send mail via an account of the customer

Option 1: send from your own domain
You can then create an email address for each customer. Suppose your application domain name is "myapp.com". You have 2 customers who use your application. These are the companies:
- company-X (have their own website / mail)
- company-Z (have their own website / mail

You now create an e-mail address for every customer, namely:
- company-X@myapp.com
- company-Y@myapp.com

When the company uses the e-mail functionality within your application, they use the above e-mail address.
Mail will now be sent FROM your own domain name WITH the same domain e-mail address, namely @ myapp.com

The next step is to ensure that when a reply is given to this e-mail, it also reaches the relevant company.
After all, one answers to Company-X@myapp.com and the mail ends up in your mail environment.

You now put a forward line on the mailbox of company-X@myapp.com whereby the mail is forwarded to an email address
of the company, for example info@company-X.com.

Now the mail is forwarded to the company and the communication takes place directly between company and customer
who has replyd on that mail. Company-X must, however, submit an spf record in their web environment take from myapp.com.
This indicates that company-X trusts myapp.com when sending e-mail.

Option 2: use a relay server
This is the most reliable way of sending mail. A smtp provider has everything set up to send mail optimally, continuously adapting the changing
mail rules of eg gmail, hotmail, outlook, etc. All you have to do is create accounts per customer, etc. Examples of smtp / relay server providers
are for example (there are in every country). Mostly all relay server providers have test account to send a x-amount mails for testing,:
- https://www.sendinblue.com/
- https://www.mailchimp.com/
- https://www.serversmtp.com/
- https://sendgrid.com/
- https://www.flowmail.com

You then pay an x amount for an x number of mails to be sent per month, usually it starts at 15.000-20,000 per month.

Option 3: use mail server client
This option is also applied, but may result in mail being seen as a spam.
You ask your customer to create an email address with a password. What you actually do is use this data to log in to the mail server
of the customer and send mail via that mail server.

All 3 options have advantages and disadvantages. Sending mail from a different mail address than your domain (where your application is located)
is often seen as spam. Especially when you are going to send multiple mails to the same e-mail domain within a certain time.
This specific time is different for each provider (gmail, hotmail, outlook). 

Do not forget to include the correct header information in your mail, especially when you send mail using options 1 and 2.
Header information is important because the domain is often mentioned there and then you run the risk that app domain and
mail domain are different to be.

You also have a number of other settings such as Dkim, Dmarc, Tls that affect the security of mail.

Regards Peter

Hi Peter. Thank you very much for your time exposing the points of view. Especially useful and didactic.  The reason for using gmail is as just because is simpler. After many experiences I rely more in my sergiofeitozacosta@gmail.com than in my sergiofeitoza@cognitor.com.br   ( from www.cognitor.com.br my consultancy company ). The idea here is to send very few e-mails. Only automatic confirmation messages for (few) people which is registering to use my software. I am almost stopped sending e-mails. People do not like them anymore whichever is sender. Anyway, for sending bulk e-mail divulging the engineering trainings I was used to apply I have a service from Leadlovers. I intend to stop with it this year. People now do not like anymore to receive e-mails.

I checked the 3 options which you detailed very well. They are professional ways of doing the thing.  However, my objective is just to put my rare engineering software SwitchgearDesign working in the web (free in the first 3 months – almost free after) and to forget it after.  I am dedicating most of my time to other activities and the software will remain there as a kind of heritage for younger people. I will put the link for access here next days.

So, I will try to discover what is missing in the Remote Area that makes to fail instead of working perfectly as in my home localhost. Maybe the reason is just a DLL missing in the SysWoww64 as above. Or something in my provider ( I am changing this week)

Regards and thanks again

Link to comment
Share on other sites

  • 6 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...