Recent

Author Topic: Working code to send email Yahoo to Gmail  (Read 10240 times)

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #45 on: June 28, 2025, 02:42:17 pm »
I don't have OpenSSL dll's in my exe directory. I didn't haved them at all and the code was working ok. From where do I get OpenSSL dll's?
« Last Edit: June 28, 2025, 02:53:44 pm by Bandy »

rvk

  • Hero Member
  • *****
  • Posts: 6885
Re: Working code to send email Yahoo to Gmail
« Reply #46 on: June 28, 2025, 05:44:12 pm »
I don't have OpenSSL dll's in my exe directory. I didn't haved them at all and the code was working ok. From where do I get OpenSSL dll's?
Maybe there was an open SSL dll in your search path under Windows.

But if they are not installed you are better of just copying them into your .exe directory.
Take the latest from the correct 64 bit version here
https://github.com/IndySockets/OpenSSL-Binaries
For example openssl-1.0.2u-x64_86-win64.zip for 64 bit application.

You can search for others (like 1.1 and 3.x versions) but these should work fine for Yahoo for now.

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #47 on: June 29, 2025, 11:30:04 am »
I put OpenSSL dll's from your link to my .exe folder: libeay32.dll and ssleay32.dll.

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #48 on: June 29, 2025, 12:11:47 pm »
And it works! The mail is send!

Thank you, rvk!

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #49 on: June 29, 2025, 12:50:18 pm »
It's possible to send email directly from my .exe to any email address (let's say to Gmail)? I mean to have a mail server into my .exe? I hope I was clear.

rvk

  • Hero Member
  • *****
  • Posts: 6885
Re: Working code to send email Yahoo to Gmail
« Reply #50 on: June 29, 2025, 01:04:59 pm »
It's possible to send email directly from my .exe to any email address (let's say to Gmail)? I mean to have a mail server into my .exe? I hope I was clear.
It’s possible in theory. In practice, it’s not.
Most providers have blocked outgoing port 25 to limit the risk of viruses doing exactly what you want to do. And without port 25 you can't reach the server you need to deliver mail. So you are stuck using a third party SMTP server for this.

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #51 on: June 29, 2025, 01:26:38 pm »
Can you post a link with the newest OpenSSL dll's: libeay32.dll and ssleay32.dll?

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #52 on: June 29, 2025, 01:42:49 pm »
If I want to attach a file or two to email, how the code should be modified?

dsiders

  • Hero Member
  • *****
  • Posts: 1461
Re: Working code to send email Yahoo to Gmail
« Reply #53 on: June 29, 2025, 04:11:18 pm »
Can you post a link with the newest OpenSSL dll's: libeay32.dll and ssleay32.dll?

In current SSL versions, those files are called libcrypto and libssl. Since 2018 (?).
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #54 on: June 29, 2025, 06:57:10 pm »
I think you understanded wrong, dsiders. rvk posted https://github.com/IndySockets/OpenSSL-Binaries with openssl-1.0.2u-x64_86-win64.zip, ver. 1.0.2. I was asking for a link with the newest version for OpenSSL.

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #55 on: June 29, 2025, 07:01:00 pm »
For rvk please:

1. Can you post a link with the newest OpenSSL dll's: libeay32.dll and ssleay32.dll?
2. If I want to attach a file or two to email, how the code should be modified?

rvk

  • Hero Member
  • *****
  • Posts: 6885
Re: Working code to send email Yahoo to Gmail
« Reply #56 on: June 29, 2025, 07:01:39 pm »
Can you post a link with the newest OpenSSL dll's: libeay32.dll and ssleay32.dll?
The OpenSSL 3 dll's are in there too:
https://github.com/IndySockets/OpenSSL-Binaries/tree/master/openssl-3_x

If you are going to use those, you need to use ssl_openssl3 instead of ssl_openssl in your uses clause.

As dsiders stated... the version 3 has libcrypto-3-x64.dll and libssl-3-x64.dll.
The other files are for OpenSSL 1.0.2 which isn't updated anymore (and the latest are in that directory).

If I want to attach a file or two to email, how the code should be modified?
In that case... you need to construct the complete DATA segment including the attachments.
The easiest way to do that is using mimemess and mimepart from Synapse.

Here is a function to create a complete EML part (EML is the mail which you can put in the DATA part). It's also usable for directly opening in Thunderbird and Outlook program.

Code: Pascal  [Select][+][-]
  1. uses mimemess, mimepart, synachar;
  2.  
  3. function GetEMLString(const MailFrom, MailTo, Subject: string;
  4.   const MailData: TStrings; Attachments: TStrings): string;
  5. var
  6.   Mime: TMimemess;
  7.   P: TMimePart;
  8.   S: string;
  9. begin
  10.   Mime := TMimeMess.Create;
  11.   try
  12.     //Build a header
  13.     Mime.Header.CharsetCode := UTF_8;
  14.     Mime.header.From := MailFrom;
  15.     Mime.Header.ToList.Add(MailTo);
  16.     Mime.Header.Subject := Subject;
  17.     // Create a MultiPart part
  18.     P := Mime.AddPartMultipart('mixed', nil);
  19.     // Add as first part the mail text
  20.     Mime.AddPartTextEx(MailData, P, UTF_8, True, ME_8BIT);
  21.     // Add all attachments:
  22.     for S in Attachments do Mime.AddPartBinaryFromFile(S, P);
  23.     // Compose message
  24.     Mime.EncodeMessage;
  25.     Result := Mime.Lines.Text;
  26.   finally
  27.     Mime.Free;
  28.   end;
  29. end;
  30.  
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var
  34.   Files: TStringList;
  35.   Content: TStringList;
  36. begin
  37.   Files := TStringList.Create;
  38.   Content := TStringList.Create;
  39.   try
  40.     Content.Add('This is the body.');
  41.     Content.Add('Files are attached.');
  42.     Files.Add('c:\temp\test2.bmp');
  43.     Memo1.Lines.Text := GetEMLString('test_from', 'test_to', 'subject', Content, Files);
  44.     // here you can use the data for sending the mail...
  45.   finally
  46.     Content.Free;
  47.     Files.Free;
  48.   end;
  49. end;
« Last Edit: June 29, 2025, 07:06:34 pm by rvk »

 

TinyPortal © 2005-2018