Recent

Author Topic: Can't make smtp work. Please help.  (Read 913 times)

gjunk

  • Newbie
  • Posts: 6
Can't make smtp work. Please help.
« on: September 15, 2023, 03:35:05 pm »
https://wiki.freepascal.org/Synapse_-_Email_Examples
I used Example 4.
I have entered and compiled the error checking version of this code using synapse4.
It compiles and runs.
I get the following error in the memo box when I click on button1.

Other undefined Status
SMTP Login: Failed - does server exist? does it accept mail?

I have tried it with smtp servers from Comcast, Gmail and ABQoff.
The emails work both sending and receiving in Thunderbird so the addresses and passwords are correct.
I have tried both port 465 and port 587.
Am I missing something?

procedure SendMail(User, Password, MailFrom, MailTo, SMTPHost, SMTPPort: string; MailData: string); 
procedure TForm1.Button1Click(Sender: TObject);
begin
  SendMail(
    'gjunk@comcast.net',              // Name if authentication required
    'Password',                       // Password if authentication required
    'gjunk@comcast.net',              // MailFrom
    '1test@abqoff.com',              // MailTo
    'smtp.comcast.net',            // Mail server to send to
    '465',                            // Mail server port
    'To: 1test@abqoff.com'           // Otherwise To: is blank on receipt
    + LineEnding + 'Subject: Test'   // Otherwise Subject: is blank on receipt
    + LineEnding +'Gday!'            // Email body
    + LineEnding);
end;     

bobby100

  • Full Member
  • ***
  • Posts: 155
    • Malzilla
Re: Can't make smtp work. Please help.
« Reply #1 on: September 15, 2023, 03:54:44 pm »
Did you included ssl_openssl in uses clausure?
Did you put the ssleay32.dll in the same directory as your executable?
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

gjunk

  • Newbie
  • Posts: 6
Re: Can't make smtp work. Please help.
« Reply #2 on: September 15, 2023, 04:08:41 pm »
ssl_openssl is in the uses clause.
ssleay32.dll is in the exe directory.


TRon

  • Hero Member
  • *****
  • Posts: 1841
Re: Can't make smtp work. Please help.
« Reply #3 on: September 15, 2023, 05:25:26 pm »
As a note: comcast seem to require that you to enable 3th party access  Did you configured that ?

bobby100

  • Full Member
  • ***
  • Posts: 155
    • Malzilla
Re: Can't make smtp work. Please help.
« Reply #4 on: September 15, 2023, 05:35:33 pm »
Could you download the SMTP Test Suite and test your connection with the SMTP Client?
https://sourceforge.net/projects/smtp-test-suite/

Just use the same parameters as in your code, and see the response.

If it works for you, take a look at the code of SMTP Test Suite - it is also based on Synapse
« Last Edit: September 15, 2023, 05:37:08 pm by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

rvk

  • Hero Member
  • *****
  • Posts: 5648
Re: Can't make smtp work. Please help.
« Reply #5 on: September 15, 2023, 07:03:17 pm »
I'm not sure from when that example is, but it doesn't work anymore.

When you use port 587, you want TLS. If you use port 465 you want SSL.
At least... that's how it is with smtp.gmail.com.

So the line  if SMTPPort<> '25' then SMTP.FullSSL:=true; is not correct.

You want:
Code: Pascal  [Select][+][-]
  1. if SMTPPort = '465' then SMTP.FullSSL := True;

Or if you are sure you are going to use 587 then you can just comment out the FullSSL := true line.

Above changes worked for me.

I think port 587 needs to use the STARTTLS.
And when using FullSSL the STARTTLS is ignored (see the login code) and SSL is done automatically on connect.
(but for smtp.gmail.com that's apparently not allowed.)
« Last Edit: September 15, 2023, 07:09:37 pm by rvk »

gjunk

  • Newbie
  • Posts: 6
Re: Can't make smtp work. Please help.
« Reply #6 on: September 18, 2023, 10:46:50 am »
As a note: comcast seem to require that you to enable 3th party access  Did you configured that ?
I have my comcast accounts set up for 3rd party access.

gjunk

  • Newbie
  • Posts: 6
Re: Can't make smtp work. Please help.
« Reply #7 on: September 18, 2023, 10:56:09 am »
It seems that comcast is turning off my email access after x number of failed access attempts.
I understand now why they are the most hated company in the world.
It takes me hours to get my access restored.
I will try the 465 and 537 changes when I get some service back.
Can anyone recommend a free email service to use for testing.

rvk

  • Hero Member
  • *****
  • Posts: 5648
Re: Can't make smtp work. Please help.
« Reply #8 on: September 18, 2023, 11:01:12 am »
Can anyone recommend a free email service to use for testing.
gmail?

For gmail you do need to use an App password. Regular passwords are not allowed for smtp access.

delphius

  • Jr. Member
  • **
  • Posts: 65
Re: Can't make smtp work. Please help.
« Reply #9 on: September 18, 2023, 11:02:02 am »
Can anyone recommend a free email service to use for testing.

Gmail?!  ::)

You can look under the hood of smtp connecting to gmail with my proof of concept native pascal tls sendmail unit based on Cryptlib
« Last Edit: September 18, 2023, 11:09:50 am by delphius »
fpmtls - ssl/tls 1.3 implementation in pure pascal
fpmailsend - sending a simple email message
pascal-webui - use web browser as gui and fpc as backend

 

TinyPortal © 2005-2018