Recent

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

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #30 on: April 04, 2022, 07:59:51 pm »
And did you also set the option to allow apps to use less secure sign in?
(This is a separate option)

As stated by the link bobby already gave you:
Quote
To resolve, go to https://login.yahoo.com/account/security and then enable the option to allow apps that use less secure sign in.
I don't see/have the option to allow apps that use less secure sign in.

bobby100

  • Sr. Member
  • ****
  • Posts: 301
    • Malzilla
Re: Working code to send email Yahoo to Gmail
« Reply #31 on: April 04, 2022, 08:15:52 pm »
I did a little research on the net, and it seems that Yahoo (since 20.10.2020) won't allow third-party apps if they are not using Oauth2 authentication.
I can't help you here, I have no clue about Oauth2.

https://support.mozilla.org/en-US/kb/thunderbird-and-yahoo

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #32 on: April 04, 2022, 08:37:48 pm »
Please help me...

bobby100

  • Sr. Member
  • ****
  • Posts: 301
    • Malzilla
Re: Working code to send email Yahoo to Gmail
« Reply #33 on: April 04, 2022, 08:45:20 pm »
You'll need to wait for rvk.
I was ready to help, but this goes behind my knowledge.

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Working code to send email Yahoo to Gmail
« Reply #34 on: April 04, 2022, 09:42:36 pm »
I did a little research on the net, and it seems that Yahoo (since 20.10.2020) won't allow third-party apps if they are not using Oauth2 authentication.
I think that's when they implemented the app password mechanisme (instead of the yahoo password).

I tried with my old account but I got a lot of troubles signing in. one time it worked and created an app password and with a few attempts for port I also got the '535 5.7.0 (#AUTH005) Too many bad auth attempts.'.

I wanted to create a new app password but now I can't login (it gives me Uh-oh... We can’t sign you in right now. and another time a timeout error).
It seems yahoo is really really unstable.

If it would really need OAuth2 then I can't help either because I only have experience with the Google OAuth2.
(but I still think app password should work)

Edit: Can login again and a new app password still fives '535 5.7.0 (#AUTH005) Too many bad auth attempts.' inside TSMTPSend.AuthPlain.

Edit 2: Aaaaargh. Now I can get a mail out. With the exact code from the start page and a new fresh app password.

So, no, OAuth2 isn't needed.
But I wouldn't rely on yahoo always working flawlessly with the issues they are having.

Code: Pascal  [Select][+][-]
  1. if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', 'Subject: test' + #13#10#13#10 + 'test') then
  2.   Memo1.Lines.Add('success')
  3. else
  4.   Memo1.Lines.Add('error');

Edit 3: Now the other older app password works also again. So maybe it was a temporary issue with yahoo.
(hence my reluctance if you want to use this in production code)
« Last Edit: April 04, 2022, 09:52:08 pm by rvk »

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #35 on: April 05, 2022, 09:26:32 am »
And what is the complete working code for sending email from Yahoo to Gmail, please rvk?

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Working code to send email Yahoo to Gmail
« Reply #36 on: April 05, 2022, 09:32:07 am »
And what is the complete working code for sending email from Yahoo to Gmail, please rvk?
The exact code from the wiki page linked on the first page in this topic.
Call-code I showed you in my last post.

So this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   ..., smtpsend, ssl_openssl;
  3.  
  4. function SendMail(const User, Password, MailFrom, MailTo, SMTPHost, SMTPPort, MailData: string): Boolean;
  5. var
  6.   SMTP: TSMTPSend;
  7.   sl:TStringList;
  8. begin
  9.   Result:=False;
  10.   SMTP:=TSMTPSend.Create;
  11.   sl:=TStringList.Create;
  12.   try
  13.     sl.text:=Maildata;
  14.     SMTP.UserName:=User;
  15.     SMTP.Password:=Password;
  16.     SMTP.TargetHost:=SMTPHost;
  17.     SMTP.TargetPort:=SMTPPort;
  18.     SMTP.AutoTLS:=true;
  19.     if SMTPPort<> '25' then
  20.       SMTP.FullSSL:=true;
  21.     if SMTP.Login then
  22.     begin
  23.       Result:=SMTP.MailFrom(MailFrom, Length(MailData)) and
  24.          SMTP.MailTo(MailTo) and
  25.          SMTP.MailData(sl);
  26.       SMTP.Logout;
  27.     end;
  28.   finally
  29.     SMTP.Free;
  30.     sl.Free;
  31.   end;
  32. end;
  33.  
  34. // ...
  35.  
  36. if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', 'Subject: test' + #13#10#13#10 + 'test') then
  37.   Memo1.Lines.Add('success')
  38. else
  39.   Memo1.Lines.Add('error');

Edit: Just ran the code again and still 'success' for me.
Although now I receive them with a delay of a few minutes.
(Also make sure your 'data' is well formed with subject, to etc because otherwise it could be seen as spam. The one liner worked for me but spamassassin did add some score to it.)
« Last Edit: April 05, 2022, 10:03:02 am by rvk »

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #37 on: April 05, 2022, 10:52:37 am »
And what is the complete working code for sending email from Yahoo to Gmail, please rvk?
The exact code from the wiki page linked on the first page in this topic.
Call-code I showed you in my last post.

So this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   ..., smtpsend, ssl_openssl;
  3.  
  4. function SendMail(const User, Password, MailFrom, MailTo, SMTPHost, SMTPPort, MailData: string): Boolean;
  5. var
  6.   SMTP: TSMTPSend;
  7.   sl:TStringList;
  8. begin
  9.   Result:=False;
  10.   SMTP:=TSMTPSend.Create;
  11.   sl:=TStringList.Create;
  12.   try
  13.     sl.text:=Maildata;
  14.     SMTP.UserName:=User;
  15.     SMTP.Password:=Password;
  16.     SMTP.TargetHost:=SMTPHost;
  17.     SMTP.TargetPort:=SMTPPort;
  18.     SMTP.AutoTLS:=true;
  19.     if SMTPPort<> '25' then
  20.       SMTP.FullSSL:=true;
  21.     if SMTP.Login then
  22.     begin
  23.       Result:=SMTP.MailFrom(MailFrom, Length(MailData)) and
  24.          SMTP.MailTo(MailTo) and
  25.          SMTP.MailData(sl);
  26.       SMTP.Logout;
  27.     end;
  28.   finally
  29.     SMTP.Free;
  30.     sl.Free;
  31.   end;
  32. end;
  33.  
  34. // ...
  35.  
  36. if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', 'Subject: test' + #13#10#13#10 + 'test') then
  37.   Memo1.Lines.Add('success')
  38. else
  39.   Memo1.Lines.Add('error');

Edit: Just ran the code again and still 'success' for me.
Although now I receive them with a delay of a few minutes.
(Also make sure your 'data' is well formed with subject, to etc because otherwise it could be seen as spam. The one liner worked for me but spamassassin did add some score to it.)
It works fine, thanks rvk!!!

kiyo

  • New Member
  • *
  • Posts: 10
Re: Working code to send email Yahoo to Gmail
« Reply #38 on: February 01, 2025, 01:13:41 pm »
Can you send a Mail from YahooMail to Gmail?
I use a Windows PC.
I can send emails from Yahoo Mail to Gmail using Thunderbird.
, so I think my ID and password are correct.
Yahoo Mail's security policy has changed so it doesn't work anymore.
How can I fix this?

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Working code to send email Yahoo to Gmail
« Reply #39 on: February 01, 2025, 02:33:13 pm »
Yahoo Mail's security policy has changed so it doesn't work anymore.
The code above still works correctly. BUT... you do need to create a complete DATA segment with all mail elements.
That means you need to have the From: line in there too. The To: isn't strictly needed (I noticed) but it's best to also include it.

So the data needs to look like:

Code: [Select]
From: my_email@yahoo.com
To: user@domain.com
Subject: test


body of mail
multiple lines

For me these are the changes:

Code: Pascal  [Select][+][-]
  1. var
  2.   sl: TStringList;
  3. begin
  4.   sl := TStringList.Create;
  5.   try
  6.     sl.Add('From: my_email@yahoo.com');
  7.     sl.Add('To: user@domain.com');
  8.     sl.Add('Subject: Test');
  9.     sl.Add('');
  10.     sl.Add('');
  11.     sl.Add('body of mail');
  12.     sl.Add('multiple lines');
  13.     if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', sl.Text)
  14.       Writeln('success')
  15.     else
  16.       Writeln('error');
  17.   finally
  18.     sl.Free;
  19.   end;
  20.   readln;
  21. end.

Don't forget that you can't use your own password but need to make an APP PASSWORD in security settings to use in the mail line.
https://login.yahoo.com/myaccount/security/

kiyo

  • New Member
  • *
  • Posts: 10
Re: Working code to send email Yahoo to Gmail
« Reply #40 on: February 01, 2025, 10:31:02 pm »
It worked, thank you.
yahoo app password is not supported here in Japan.
So I can't generate it.

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Working code to send email Yahoo to Gmail
« Reply #41 on: February 01, 2025, 10:55:27 pm »
It worked, thank you.
yahoo app password is not supported here in Japan.
So I can't generate it.
Ha, ok. So in Japan it still works with your normal password.
Glad you got it working.

Bandy

  • Jr. Member
  • **
  • Posts: 84
Re: Working code to send email Yahoo to Gmail
« Reply #42 on: June 27, 2025, 04:06:23 pm »
The code from Bandy's (my) post on: April 05, 2022, 10:52:37 am, where I say: "It works fine, thanks rvk!!!" is not doing the login anymore at "if SMTP.Login then" line.

This is the code from my post on: April 05, 2022, 10:52:37 am:

uses
  ..., smtpsend, ssl_openssl;
 
function SendMail(const User, Password, MailFrom, MailTo, SMTPHost, SMTPPort, MailData: string): Boolean;
var
  SMTP: TSMTPSend;
  sl:TStringList;
begin
  Result:=False;
  SMTP:=TSMTPSend.Create;
  sl:=TStringList.Create;
  try
    sl.text:=Maildata;
    SMTP.UserName:=User;
    SMTP.Password:=Password;
    SMTP.TargetHost:=SMTPHost;
    SMTP.TargetPort:=SMTPPort;
    SMTP.AutoTLS:=true;
    if SMTPPort<> '25' then
      SMTP.FullSSL:=true;
    if SMTP.Login then {here the login is not done ok and the mail is not send anymore}
    begin
      Result:=SMTP.MailFrom(MailFrom, Length(MailData)) and
         SMTP.MailTo(MailTo) and
         SMTP.MailData(sl);
      SMTP.Logout;
    end;
  finally
    SMTP.Free;
    sl.Free;
  end;
end;
 
// ...
 
if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', 'Subject: test' + #13#10#13#10 + 'test') then
  Memo1.Lines.Add('success')
else
  Memo1.Lines.Add('error');

I changed the app password, but the mail still doesn't send.

Please help!!!

gues1

  • Guest
Re: Working code to send email Yahoo to Gmail
« Reply #43 on: June 27, 2025, 06:53:20 pm »
I changed the app password, but the mail still doesn't send.
Please help!!!

May be you must do what @rvk said:

Don't forget that you can't use your own password but need to make an APP PASSWORD in security settings to use in the mail line.
https://login.yahoo.com/myaccount/security/

If it doesn't works, try to use TLS with port 587

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Working code to send email Yahoo to Gmail
« Reply #44 on: June 27, 2025, 11:52:08 pm »
The code from Bandy's (my) post on: April 05, 2022, 10:52:37 am, where I say: "It works fine, thanks rvk!!!" is not doing the login anymore at "if SMTP.Login then" line.
The code still works fine. The login also works. If the login doesn't work, you might have the wrong OpenSSL dll's in your exe directory. Make sure they are correct.

You can change the following:
Code: Pascal  [Select][+][-]
  1.       if SMTP.Login then
  2.       begin
  3.         Writeln('Login ok');
  4.         Result := SMTP.MailFrom(MailFrom, Length(MailData));
  5.         Writeln('MailFrom ok ', Ord(Result), ' Result: ', SMTP.FullResult.Text);
  6.         if Result then Result := SMTP.MailTo(MailTo);
  7.         Writeln('MailTo ok ', Ord(Result), ' Result: ', SMTP.FullResult.Text);
  8.         if Result then Result := SMTP.MailData(sl);
  9.         Writeln('MailData ok ', Ord(Result), ' Result: ', SMTP.FullResult.Text);
  10.         SMTP.Logout;
  11.         Writeln('Logout ok ', ' Result: ', SMTP.FullResult.Text);
  12.       end;

That way, you see the result with each step. When OpenSSL is included, the login should work fine.

BUT... you end up with another problem...
If you use above code you'll get:
Quote
Login ok
MailFrom ok 1 Result: 250 2.1.0 Sender <you@yahoo.com> OK

MailTo ok 1 Result: 250 2.1.5 Recipient <me@meme.com> OK

MailData ok 0 Result: 554 6.6.0 Error sending message for delivery.

Logout ok  Result: 221 Service Closing transmission

error

And that's because of the following... did you read my previous post? (quoted below)

You really need to create a complete DATA segment including FROM, TO, SUBJECT and the message itself.
Yahoo cracked down on just sending a bare minimum and the things above really need to be there.
In your code you just have SUBJECT and one line. That's not enhough.
(You can use code below to create a more complete DATA segment for your message)

Yahoo Mail's security policy has changed so it doesn't work anymore.
The code above still works correctly. BUT... you do need to create a complete DATA segment with all mail elements.
That means you need to have the From: line in there too. The To: isn't strictly needed (I noticed) but it's best to also include it.

So the data needs to look like:

Code: [Select]
From: my_email@yahoo.com
To: user@domain.com
Subject: test


body of mail
multiple lines

For me these are the changes:

Code: Pascal  [Select][+][-]
  1. var
  2.   sl: TStringList;
  3. begin
  4.   sl := TStringList.Create;
  5.   try
  6.     sl.Add('From: my_email@yahoo.com');
  7.     sl.Add('To: user@domain.com');
  8.     sl.Add('Subject: Test');
  9.     sl.Add('');
  10.     sl.Add('');
  11.     sl.Add('body of mail');
  12.     sl.Add('multiple lines');
  13.     if SendMail('my_username_without_yahoo.com', 'app_password', 'my_email@yahoo.com', 'user@domain.com', 'smtp.mail.yahoo.com', '465', sl.Text)
  14.       Writeln('success')
  15.     else
  16.       Writeln('error');
  17.   finally
  18.     sl.Free;
  19.   end;
  20.   readln;
  21. end.

Still works (just tested it).

 

TinyPortal © 2005-2018