4D Mail (How to send 4d transporter email from g-suite user?)

How would 4d transporter send email from one g-suite user to other g-suite users, all within the same organization?

What 4d transporter configuration would be used?

In particular, what values for:

  1. host
  2. user
  3. password

I think this inputs you will get from your google account.
Otherwise there were already some posts:

Thanks for replying, Lutz.

Unfortunately, the first thread you cite (“Envois de mails avec Gmail”) reports the same problem I’m getting, which is “Bad credentials”.

The example Miyako provides appears to be the legacy 4D Internet Commands. I’m using the 4D’s new “Mail”.

The 2020 Summit presentation “SMTP New Transporter” does not show how to use Mail with Google’s G-Suite.

How do I send emails from 4D, where the 4D user is in an organization that uses Google Mail. The 4D user will be sending emails (from 4D) to other users within the same organization.

In other words, all users use Google Mail.

How do I resolve the “Bad credentials”, where Google rejects the email from 4D?

Please take a detailed look at this post by Th. Maul:

It has nothing to do with what organization the users are in, AFAIK. If Google has special conditions in this case, please consult their manuals.
But I think even if you use Gmail in an organization, you’re using an external service.

It’s always difficult to handle email with Gmail. And they change the API and the conditions a lot over time.

With (and without) an app password, I still get “Bad credentials”.

How do I prevent Google from rejecting the 4D Mail connection?

Mail returns the error "Bad credentials"

When I verify the GMail connection, I get “Bad credentials”.

failure

I am verifying by calling:

C_OBJECT($smtp;$status)

  // creation of the transporter SMTP object with the information entered in the form
$smtp:=SMTP New transporter(Form.smtp)

  // Connection check, to verify if  the information intered are OK
$status:=$smtp.checkConnection()

  // Verification if connection check is a success or not, and display a message

ALERT(JSON Stringify($status;*))



The SMTP Error Log shows:

1	2020-06-26T15:18:07.423	1	1	### SMTP Connected to 'smtp.gmail.com' on port 587. (unsecured)
2	2020-06-26T15:18:07.443	1	1	S < "220 smtp.gmail.com ESMTP i10sm11175458qkn.126 - gsmtp"
3	2020-06-26T15:18:07.443	1	1	C > "EHLO [10.0.1.7]"
4	2020-06-26T15:18:07.479	1	1	S < "250-smtp.gmail.com at your service, [2601:86:4300:6851:f1b1:3521:653b:79e]"
5	2020-06-26T15:18:07.479	1	1	S < "250-SIZE 35882577"
6	2020-06-26T15:18:07.479	1	1	S < "250-8BITMIME"
7	2020-06-26T15:18:07.479	1	1	S < "250-STARTTLS"
8	2020-06-26T15:18:07.479	1	1	S < "250-ENHANCEDSTATUSCODES"
9	2020-06-26T15:18:07.479	1	1	S < "250-PIPELINING"
10	2020-06-26T15:18:07.479	1	1	S < "250-CHUNKING"
11	2020-06-26T15:18:07.479	1	1	S < "250 SMTPUTF8"
12	2020-06-26T15:18:07.480	1	1	C > "STARTTLS"
13	2020-06-26T15:18:07.512	1	1	S < "220 2.0.0 Ready to start TLS"
14	2020-06-26T15:18:07.516	1	1	### SMTP Encrypted TLS session started.
15	2020-06-26T15:18:07.516	1	1	C > "EHLO [10.0.1.7]"
16	2020-06-26T15:18:07.599	1	1	S < "250-smtp.gmail.com at your service, [2601:86:4300:6851:f1b1:3521:653b:79e]"
17	2020-06-26T15:18:07.599	1	1	S < "250-SIZE 35882577"
18	2020-06-26T15:18:07.599	1	1	S < "250-8BITMIME"
19	2020-06-26T15:18:07.599	1	1	S < "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
20	2020-06-26T15:18:07.599	1	1	S < "250-ENHANCEDSTATUSCODES"
21	2020-06-26T15:18:07.599	1	1	S < "250-PIPELINING"
22	2020-06-26T15:18:07.599	1	1	S < "250-CHUNKING"
23	2020-06-26T15:18:07.599	1	1	S < "250 SMTPUTF8"
24	2020-06-26T15:18:07.599	1	1	C > "AUTH LOGIN"
25	2020-06-26T15:18:07.632	1	1	S < "334 VXNlcm5hbWU6"
26	2020-06-26T15:18:07.632	1	1	C > "************************************"
27	2020-06-26T15:18:07.660	1	1	S < "334 UGFzc3dvcmQ6"
28	2020-06-26T15:18:07.660	1	1	C > "************************"
29	2020-06-26T15:18:08.269	1	1	S < "535-5.7.8 Username and Password not accepted. Learn more at"
30	2020-06-26T15:18:08.269	1	1	S < "535 5.7.8  https://support.google.com/mail/?p=BadCredentials i10sm11175458qkn.126 - gsmtp"
31	2020-06-26T15:18:08.269	1	1	C > "QUIT"
32	2020-06-26T15:18:08.296	1	1	S < "221 2.0.0 closing connection i10sm11175458qkn.126 - gsmtp"
33	2020-06-26T15:18:08.297	1	1	### SMTP Connection closed



The SMTP codes (in the above log) appear to be:

2xx - Success
3xx - Redirection
5xx - Permanent errors

220 - SMTP Service ready
221 - Service closing
250 - Requested action taken and completed
334 - the requested security mechanism is accepted
535 - Authentication failed


Questions:

line #19:

Is this asking or expecting a specific protocol?

Line #26 and Line #28

What is the significance of these lines?

Is the values “VXNlcm5hbWU6” a token?
Is the value “UGFzc3dvcmQ6” a token?

Line #30

The Authentication failure is puzzling, because.

  1. The user name is the gmail user’s name

  2. The password is an app specific password.

???

How does Mail send emails from a GMail account?

I did as Thomas said to: created an App password, then used that as the password in the credentials sent and it worked!
UserName: usual; Password: the google app password.
Functioned perfectly for me. – Chris

Hi Chris,

There must be something different between your situation and mine.

I wonder what the difference is?

Several questions:

  1. Is the Google account a G-Suite account?
  2. Does the Google account have 2-step verification enabled?
  3. Are you using Mail’s “Transporter”?
  4. What version of 4D?
  1. It is not a G-suite account. just my macprogrammmer@gmail.com
  2. It has 2-step verification enabled. In fact, when I generated the app password and used it the first time in 4D, I seem to remember it may have sent a verification text, but perhaps I am just imagining that.
  3. I used SMTP_Transporter.
  4. V18r2

Based on one of 4D’s code examples:

$mail:=New object
$mail.subject:=“Test email: Hello world!”
$mail.textBody:=“Test email \r\n This is just a test email \r\n Please ignore it”
$mail.htmlBody:=“

Test email

This is just a test email
Please ignore it”
$mail.from:=Storage.env.user.user
$mail.to:=“ctbelanger@gmail.com
$smtp:=SMTP New transporter(Storage.env.user)

ON ERR CALL(“onerr”)
// Send the mail according to the mail information entered in the form
$status:=$smtp.send($mail)
ON ERR CALL("")

// Verification if send mail is a success or not and display a message
If ($status.success)
ALERT(“Mail has been sent”)
Else
If ($status.status=0)
ARRAY LONGINT($tcodes;0)
ARRAY LONGINT($tcmps;0)
ARRAY TEXT($tmess;0)
GET LAST ERROR STACK($tcodes;$tcmps;$tmess)
ALERT("An error occurred: "+$tmess{1})
Else
ALERT("An error occurred: "+$status.statusText)
End if
End if

I have the transporter defined in Storage.env.user (since it is always the same for a user).
The relevant attributes for the Storage.env.user.user:
.user macprogrammer@gmail.com
.password (the google app password)
.host smtp.gmail.com (perhaps this is wrong for you???)

.port 587 (longint) (perhaps this is wrong for you???)

.acceptUnsecureConnection false (boolean)

[Note: the .user actually has a bunch of other attributes in my system, but only some of them apply to email and having them ‘mixed’ with my other attributes does not seem to cause any issues!]

1 Like

Like Jeremy asked, and as explained in the support.google.com page given in the error message, did you allow less secure apps? Google considers SMTP to be inherently “less secure”, because one only needs to know the username and password (1-factor).

SMTP New transporter is “less secure”.

I never knew Jeremy asked about if I ‘allowed less secure apps’. I guess you inferred that from his question. All I know is that I have 2-step verification on, and using App passwords [which are not the easiest to crack; and I cannot access my account with my ‘standard’ password using 4D, so I imagine it is as secure as it can be in a password situation]. If that makes me unsecure, I guess I live with it :slight_smile:

google settings

I was just trying to answer a question in a way that could enlighten a fellow developer. Maybe he had a wrong port, or host ?? I tried to check my gmail account settings but cannot readily see where I would make it ‘less secure’; if you let me know where the setting is I can answer your question.
What I understand from the support page you cited, IFF one uses 2-step verification and an app password, that is good. You do not need to ‘allow less secure apps’ to have access UNLESS you do not use 2-step verification. I’m positive I have NOT allowed less secure apps.
I let 4D worry about the details on SMTP; they seem to have done a fine job and I’m happy I can do what I need to.

I appreciate your contribution to the discussion, and you are right, I should not have posted “in reply to” your post which was just a suggestion made in the hopes of helping the previous comment.

I think the main difference here is that you are using a gmail.com account (is that right?) but the original post is about a G Suite account, which is by definition not a free gmail.com account.

Okay. I never needed to send emails from 4D through my own G-suite account (which I also have).