Recent

Author Topic: How Send Email (Gmail, Hotmail, Yahoo)  (Read 1919 times)

Bandy

  • New Member
  • *
  • Posts: 35
How Send Email (Gmail, Hotmail, Yahoo)
« on: March 15, 2022, 06:21:30 pm »
Hello,

I want to send email from Yahoo to Gmail and I receive error message from attachment picture. How can be FIXED?
This is my code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   RTTICtrls, XMailer, DateUtils, WinInet;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button4: TButton;
  17.     procedure Button4Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure SendMail(nume, mesaj:string);
  34. var
  35.     Mail: TSendMail;
  36. begin
  37.   Mail := TSendMail.Create;
  38.   try
  39.       // Mail
  40.       Mail.Sender := 'bandy@yahoo.com';
  41.       Mail.Receivers.Add('bandy@gmail.com');
  42.       Mail.Subject := 'Notify';
  43.       Mail.Message.Add(mesaj);
  44.       //Mail.Attachments.Add('C:\No File.txt');  // to send files, optional
  45.       // SMTP
  46.       Mail.Smtp.UserName := 'bandy@yahoo.com';
  47.       Mail.Smtp.Password := 'password';
  48.       Mail.Smtp.Host := 'smtp.mail.yahoo.com';
  49.       Mail.Smtp.Port := '587';
  50.       Mail.Smtp.SSL := True;
  51.       Mail.Smtp.FullSSL := False;  // thanks rvk
  52.       Mail.Smtp.TLS := True;
  53.       Mail.Send;
  54.       //ShowMessage('SUCCESS :) ');
  55.     {except
  56.       on E:Exception do
  57.  
  58.     end;}
  59.     finally
  60.       Mail.Free;
  61.     end;
  62. end;
  63.  
  64. procedure TForm1.Button4Click(Sender: TObject);
  65. begin
  66.   SendMail('','test');
  67. end;
  68.  
  69. end.

[Edited to add code tags - PLEASE read How to use the Forum.]
« Last Edit: March 15, 2022, 10:36:02 pm by trev »

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #1 on: March 15, 2022, 07:04:17 pm »
I want to send email from Yahoo to Gmail and I receive error message from attachment picture. How can be FIXED?
What version of openssl are you using?
Try one of the later versions.

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #2 on: March 15, 2022, 07:09:52 pm »
How can I find version of openssl?

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #3 on: March 15, 2022, 07:18:51 pm »
You didn't put any openssl dll besides your exe program?

In that case your system might not even have an openssl installed which would also result in that error.

What OS and what bitness of FPC are you using? 32 bit or 64 bit?

Download the correct openssl for bitness here
https://indy.fulgan.com/SSL/
And put those dll besides you .exe and try again.

(For example openssl-1.0.2u-x64_86-win64.zip for FPC 64 bit)
« Last Edit: March 15, 2022, 07:21:54 pm by rvk »

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #4 on: March 15, 2022, 07:23:02 pm »
Windows 10 64bit and Lazarus 2.2.0

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #5 on: March 15, 2022, 07:30:36 pm »
Windows 10 64bit and Lazarus 2.2.0
Then unzip the openssl-1.0.2u-x64_86-win64.zip from earlier link to your exe directory.
(If Lazarus itself is 64 bit too)

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #6 on: March 15, 2022, 07:35:02 pm »
I done what you told me and still the same error.

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #7 on: March 15, 2022, 07:37:46 pm »
I have Lazarus 2.2.0 for 64bit.

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #8 on: March 15, 2022, 07:40:13 pm »
I have Lazarus 2.2.0 for 64bit.
Then you should keep those dll files in the exe directory. They are needed (and depending on the system version isn't always best).

Not sure why you still get the error then.

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #9 on: March 16, 2022, 01:48:45 pm »
Please HELP ME! I want to send email from Yahoo to Gmail and I receive error message from attachment picture. How can be FIXED? My code is above.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #10 on: March 16, 2022, 05:38:06 pm »
The error message has nothing to do with OpenSSL itself, so you need to stop focusing on that.  The error is coming from a failed SMTP MAIL FROM command, long after an SSL/TLS session has been negotiated, and the Yahoo account has been logged in to.  Though, I do find it interesting that the 2nd line of the exception's Message (which is supposed to contain the actual SMTP error message from the server) is basically nonsense, it doesn't look like a valid SMTP error.  Which could indicate a corrupted SMTP communication.

Something else I notice - in the source code of xmailer's TSendMail.Send() method, when it calls Synapse's TSmtpSend.MailFrom() method, it is setting the Size parameter to an incorrect value.  It is setting the parameter to the character length of the Sender's email address, but it should be setting the parameter to the byte size of the email message instead.  So, that could potentially be causing Yahoo to reject the command.
« Last Edit: March 19, 2022, 01:05:45 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #11 on: March 18, 2022, 09:25:05 pm »
I want to send email from Yahoo to Gmail and I receive error in attachment. How can be fixed? Please don't delete my post.
Remy already answered you?

Fix the xmailer code yourself to see if he is right (i.e. changing the size parameter in that line) or don't use xmailer.


[Edited to make sense after two identical topics merged. OP has been banned in the meantime (not by me).]
« Last Edit: March 18, 2022, 10:54:41 pm by trev »

Bandy

  • New Member
  • *
  • Posts: 35
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #12 on: March 18, 2022, 09:47:19 pm »
And what should I use instead of xmailer, please?

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How Send Email (Gmail, Hotmail, Yahoo)
« Reply #13 on: March 18, 2022, 10:04:38 pm »
And what should I use instead of xmailer, please?
You could use Synapse directly. Xmailer is just a wrapper around that.

There are plenty of examples here on the forum.
(Search for part of the code like FullSSL and you'll find them)

For example https://forum.lazarus.freepascal.org/index.php/topic,54733.msg406913.html#msg406913

Otherwise you can fix xmailer.pas at around line 522
FSmtp.MailFrom(VSenderAddr, Length(VSenderAddr))
The length should be of your data (not sure at this moment what exactly).
You could also try setting it to 0 (I thought that size was ommited in that case).

« Last Edit: March 18, 2022, 10:10:30 pm by rvk »

 

TinyPortal © 2005-2018