again synapse and gmail lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- krolikbest · 2021-05-23 11:32 Hi, I thought that it's simply thing, use this code from link https://wiki.freepascal.org/Synapse#Sending_email to send e-mail to my google account but something i can't or don't understand. So my code looks like (simplified) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.SendMail(MailFrom, MailTo , MailData: string): Boolean;var  SMTP: TSMTPSend;  sl:TStringList; begin   Result:=False;  SMTP:=TSMTPSend.Create;  sl:=TStringList.Create;  try    sl.text:=Maildata;    SMTP.UserName:='myaccount@gmail.com';    SMTP.Password:='mypasswd';    SMTP.TargetHost:='smtp.gmail.com';    SMTP.TargetPort:='465';    SMTP.AutoTLS:=true;    SMTP.FullSSL:=true;    if SMTP.Login then    begin      result:=SMTP.MailFrom(MailFrom, Length(MailData)) and         SMTP.MailTo(MailTo) and         SMTP.MailData(sl);      SMTP.Logout;      showmessage('logged');    end;  finally    SMTP.Free;    sl.Free;  end;end;and button.OnClick looks like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SendMail('otheraddr@wp.pl', 'myaccount@gmail.com','122334'); In uses there are units  smtpsend, ssl_openssl, openssl, opensslsockets;  I wonder if username is the same as 'myaccount@gmail.com' in my case?. But  i get message 'logged' so I assume that it is. But nothing is received in thunderbird. Maybe someone has got similar problem with gmail. Other my account on different host works fine using similar code. Regards, ---------------------------------------------------------------------- lucamar · 2021-05-23 12:28 If your source host (wp.pl) stores the "sent" messagges, have you checked whether the message is there? That would meant it was sent but for some reason Google rejected it; you might have received a message back at wp.pl telling you so and why, but it doesn't always happen. That would be my first step: make sure the message was sent and wahtthe reply (if any) was. Note that GMail (as most other big mailers) uses lots of "security" and "anti-spam" features (like rather stringent source host checks) that interfere a lot with "home-grown" mail programs, so your message might have got rejected (silently or not) or sent to your gmail spam folder. ---------------------------------------------------------------------- krolikbest · 2021-05-23 13:44 The mailbox of wp.pl is empty in every folder. So it looks like the message has been sent? There is workaround if at google account I choose less secure access but consider this way as bad solution. ---------------------------------------------------------------------- nanobit · 2021-05-23 17:29 For investigation you can collect feedback from TSMTPSend.fullResult.text after each command (Login, mailFrom(), ...). ---------------------------------------------------------------------- krolikbest · 2021-05-23 18:38 Exactly it's what I did and in progress (530 5.7.0). Sooner or later I'll resolve it so please take this subject as a closed. Im sure I have something wrong with my e-mail address. ---------------------------------------------------------------------- rvk · 2021-05-24 08:54 Quote from: krolikbest on May 23, 2021, 03:44:40 pmThere is workaround if at google account I choose less secure access but consider this way as bad solution. You shouldn't use the less secure option. It is better to create a specific App-password. You can use that with your username. The App- password is then specifically for your app and sending mail. It's also not the recommended way but much much better than setting the "less secure" option. https://support.google.com/accounts/answer/185833?hl=en ---------------------------------------------------------------------- krolikbest · 2021-05-25 08:53 My workaround - there  must be some sender address (let's say myaddr1@wp.pl) and receiver is gmail address (mygmailaddr@gmail.com). My code slightly differs from my previous (I added Mime) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.SendMail(User, Password, MailFrom, MailTo, SMTPHost,  SMTPPort: string; MailData: string): Boolean;var  SMTP: TSMTPSend;  sl:TStringList;  MimeMsg : TMimeMess; begin  Result:=False;  SMTP:=TSMTPSend.Create;  sl:=TStringList.Create;  MimeMsg := TMimeMess.Create;  sl.text:=Maildata;  try    MimeMsg.Header.From := MailFrom;    MimeMsg.Header.ToList.Add(mailTo);    MimeMsg.Header.Subject := 'Test message';    MimeMsg.AddPartText(sl,nil);     SMTP.UserName:=User;    SMTP.Password:=Password;    SMTP.TargetHost:=SMTPHost;    SMTP.TargetPort:=SMTPPort;    mimeMsg.EncodeMessage;    SMTP.FullSSL:=true; //wp.pl use only SSL    if SMTP.Login then    begin      showmessage(smtp.ResultString);       SMTP.MailFrom(MailFrom, Length(mimeMsg.Lines.Text));      SMTP.MailTo(MailTo);      if SMTP.MailData(mimeMsg.Lines) then        SMTP.Logout;      showmessage(smtp.ResultString);    end;  finally    freeAndNil(mimeMsg);    SMTP.Free;    sl.Free;  end;end;                         and in button.OnClick Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  SendMail('myaddr1@wp.pl', 'passwd', 'myaddr1@wp.pl', 'mygmailaddr@gmail.com', 'smtp.wp.pl', '465','New Hope');       This is raw code so one has to polish and to adapt to the needs. As you see is used additional address in order to send to gmail address. On the other hand this solution doesn't leave messages on wp.pl domain so in my case that is good. Of course one can it change using Mime. Regards,