Recent

Author Topic: Sending email with Indy  (Read 16298 times)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Sending email with Indy
« Reply #15 on: April 23, 2019, 09:17:41 pm »
You are not allowed to just use smtp.gmail.com with your normal username and password.

You are if you enable "Unsecure apps" in your Gmail settings.  But, of course, that is not advisable.

You can either implement OAuth2, which I imagine is beyond your skillset, or you need to use a "App password" instead of your normal gmail password.

Indy does not support OAuth2 at this time, but generating an App Password works fine, I use app passwords all the time when I am testing Gmail SMTP with Indy.

I added the TIdSSLIOHandlerSocketOpenSSL component to the form and set its port. After it I could change the UseTLS to 'utUseRequireTLS' in SMTP.

The correct UseTLS value to use on the client side is utUseExplicitTLS on port 25 and 587, and utUseImplicitTLS on port 465.  Do not use utUseRequireTLS on the client side, it is meant to be used by servers instead.
« Last Edit: April 23, 2019, 09:19:33 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #16 on: April 23, 2019, 09:38:27 pm »
Thank you Remy for the instructions, now I changed it!

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #17 on: April 24, 2019, 12:15:52 pm »
New question guys. I'm using a Memo or SynEdit component to make the email message (html formatted).
If I send it, the recipient gets a plain text, but I want to send it as a html.
How can I achive this?

Update: meanwhile I found this https://www.indyproject.org/2005/08/17/html-messages/, not seems too simple.
« Last Edit: April 24, 2019, 02:24:10 pm by justnewbie »

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #18 on: April 24, 2019, 03:42:40 pm »
Based on the link above: there is no TIdText component in my Indy10.  :o

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #19 on: April 24, 2019, 04:17:43 pm »
Wow! I got html-email! :)
Following this: https://stackoverflow.com/questions/14323852/tidtext-missing-from-indy-10
Solution: I added these units to the Uses: IdMessage, IdAttachment, IdText, IdAttachmentFile, IdMessageParts
« Last Edit: April 24, 2019, 04:21:26 pm by justnewbie »

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #20 on: April 24, 2019, 05:05:29 pm »
Remy, I hope you are somewhere near ... would have some questions!
1./ Currently the "From" contains my email address, but my name would be better there. Is it possible?
2./ As I can see, the ipHtmlPanel cannot handle the formatting properly
(for example, this <p style="background-color: #627E20; font-weight: bold; color: #BAF2F2" >This is an other text.</p> does proper font formatting, but not for the background color).
Did I miss something or is it the normal behaviour?
3./ The sending function works great with TLS and port 587 (Gmail). What should I change in the settings to get SSL and port 465 to work? I mean, there are many options in TIdSSLIOHandlerSocketOpenSSL for SSLOptions, bit confusing.
4./ Currently I'm using this method for attachment:
Code: Pascal  [Select][+][-]
  1. Attachment := TIdAttachmentFile.Create(MailMessage.MessageParts, attFile);
It only send 1 attached file. How can I send more than 1 attached files?

4. is solved with a loop:
Code: Pascal  [Select][+][-]
  1. for i := 0 to slAttachedFiles.Count - 1 do
  2.   begin
  3.     if FileExists(slAttachedFiles[i]) then TIdAttachmentFile.Create(MailMessage.MessageParts, slAttachedFiles[i]);
  4.   end;

« Last Edit: April 24, 2019, 06:44:32 pm by justnewbie »

john horst

  • Jr. Member
  • **
  • Posts: 68
    • JHorst
Re: Sending email with Indy
« Reply #21 on: April 24, 2019, 05:46:12 pm »
Are you getting no Background color or is it not behaving as expected?

You can't enable SSLv1,2,3, it's an insecure protocol and shouldn't be used. I believe that is why he said use "utUseImplicitTLS on port 465', make sure it uses TLS on both ports.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #22 on: April 24, 2019, 06:00:05 pm »
1./ Are you getting no Background color or is it not behaving as expected?

2./ You can't enable SSLv1,2,3, it's an insecure protocol and shouldn't be used. I believe that is why he said use "utUseImplicitTLS on port 465', make sure it uses TLS on both ports.
1./ I got no background-color.
2./ With Gmail it is OK (TLS, 587), but I want to use an other SMTP which uses SSL and port 465. When I tried it, did not send the email.
« Last Edit: April 24, 2019, 06:07:58 pm by justnewbie »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Sending email with Indy
« Reply #23 on: April 24, 2019, 07:24:25 pm »
2./ As I can see, the ipHtmlPanel cannot handle the formatting properly
(for example, this <p style="background-color: #627E20; font-weight: bold; color: #BAF2F2" >This is an other text.</p> does proper font formatting, but not for the background color).
This is not normal HTML formatting for an E-mail client. You need to lookup how you need to encode correct HTML. If you send an E-mail to yourself and look at the source you'll see why.

Your example should probably be something like this (the equal sign needs to be encoded with =3D):
<p style=3D"background-color: #627E20; font-weight: bold; color: #BAF2F2">This is an other text.</p>

Not sure if Indy does this automatically or has some functions available for it.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #24 on: April 24, 2019, 07:49:37 pm »
This is not normal HTML formatting for an E-mail client. You need to lookup how you need to encode correct HTML. If you send an E-mail to yourself and look at the source you'll see why.

Your example should probably be something like this (the equal sign needs to be encoded with =3D):
<p style=3D"background-color: #627E20; font-weight: bold; color: #BAF2F2">This is an other text.</p>

Not sure if Indy does this automatically or has some functions available for it.
Uh, thanks. It's new to me, I thought it is the usual html/css thing.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Sending email with Indy
« Reply #25 on: April 24, 2019, 08:01:24 pm »
Uh, thanks. It's new to me, I thought it is the usual html/css thing.
In essence it is. But using mail the html gets send as printed-quotable. And there the = sign is reserved for encoding. So = needs to be (re)encoded as =3D. $3D is ascii 61 which is the =.

john horst

  • Jr. Member
  • **
  • Posts: 68
    • JHorst
Re: Sending email with Indy
« Reply #26 on: April 24, 2019, 08:02:09 pm »
You might need to patch to get background-color to work properly. I tried myself even encoding the = to %3D, as I expected it wouldn't work. I don't think it has to be encoded like a URL, plus it Bold etc work with out encoding so it must be reading it.

I found this. https://forum.lazarus.freepascal.org/index.php?topic=43116.5;wap2

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Sending email with Indy
« Reply #27 on: April 24, 2019, 08:14:23 pm »
You might need to patch to get background-color to work properly. I tried myself even encoding the = to %3D, as I expected it wouldn't work.
No, don't encode it as %3D. Encode it as =3D.
Those are two different encodings.
One is url encoding and the other is printed-quotable.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #28 on: April 24, 2019, 08:46:43 pm »
No, don't encode it as %3D. Encode it as =3D.
Those are two different encodings.
One is url encoding and the other is printed-quotable.
Yes, you are right, this is the proper way: style=3D"background-color: ...

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Sending email with Indy
« Reply #29 on: April 24, 2019, 08:52:41 pm »
So, these two questions remained yet:
1./ Currently the "From" contains my email address, but my name would be better there next to the sender email address.
(Example: now in Thunderbird 'from column' it looks like this: myaddress@gmail.com <myaddress@gmail.com>. I need MyName <myaddress@gmail.com>). Is it possible?
2./ The sending function works great with TLS and port 587 (Gmail). What should I change in the settings to get SSL and port 465 to work? I mean, there are many options in TIdSSLIOHandlerSocketOpenSSL for SSLOptions, bit confusing.
« Last Edit: April 24, 2019, 08:54:13 pm by justnewbie »

 

TinyPortal © 2005-2018