smtp error: 534 when sending email through gmail in golang app - email

On my golang app I use this snippet to send email from my gmail account:
func send(body string) {
from := "myaccount#gmail.com"
pass := "mysupersecretpasswd"
to := "whoever#whatever.com"
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: Hello there\n\n" +
body
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
log.Printf("smtp error: %s", err)
return
}
log.Print("sent, visit whatever)
}
I get this error instead:
smtp error: 534 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbud
5.7.14 lxVDnr-tXOckmxXi0fxExY5BKDRczBpGvMCpGWGF97jAI5DlM2oeGMDcIkvBhKT9rJAVnH
5.7.14 WP7zxssynLtkzMb35et-wxJF2AfeBhMA81QqMh2F8fkQRdf9GidA3swFnjfsUl0Pw6fiMT
5.7.14 b3zvEJyD6WAKEWcuxEGJIBTaqCtfDjipQ58cFJweUiKg1_4AJp0fGpC9ufnjBGWqWVKeW9
5.7.14 QVbUstROYK0SzjWXTTvsvZhhG3RjM> Please log in via your web browser and
5.7.14 then try again.
5.7.14 Learn more at
5.7.14 https://support.google.com/mail/answer/78754 61sm6182123wre.44 - gsmtp
I have installed postfix on my localhost. I have also allowed less secure apps to access my account.
I have also tried the same code on my VPS, but it does not send emails either.
So what could be wrong? How can I fix it?

I've copied your gist, replaced from, to and password and it works flawlessly. The only reason why this code is not working is that you are NOT allowing less secure apps in gmail.

Related

i am getting this error in laravel 8 when sending mail for forget password in user authentication that i was doing using jetstream

Expected response code 250 but got code "530", with message "530 5.7.0
Must issue a STARTTLS command first. t17sm10940193wmi.47 - gsmtp "

Classis ASP sending to smtp.gmail.com doesn't work

I need to send email from my server to smtp.gmail.com using classic ASP.
I am using the ASPEmail component and have the latest version (5.4.0.6) aspemail64.
Everything I try gives an error.
1) Just user and password
mailer.host = "smtp.gmail.com"
mailer.Username = "someone#somewhere.org"
mailer.Password = "somepass"
This gives:
Err = 530 5.7.0 Must issue a STARTTLS command first.
2) TLS and port 587
mailer.TLS = True
mailer.Port = 587
Transport Layer Security Error #30 (SMTP): 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754
3) SSL and port 465
mailer.SSL = True
mailer.Port = 465
Transport Layer Security Error #30 (SMTP): 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754
Anyone get Classic ASPEmail64 working with smtp.gmail.com?
Thanks for the answers.
I got this figured out and this information may help someone else.
You have to have a SPF record in your DNS.
https://en.wikipedia.org/wiki/Sender_Policy_Framework
Once I put that in all the weird errors went away even with the gmail security setting turned back on.
It works now with the latest ASPEmail64 and these settings.
mailer.From = "someone#somewhere.com"
mailer.Username = "someone#somewhere.com"
mailer.Password = "password"
mailer.host = "smtp.gmail.com"
mailer.TLS = True
mailer.Port = 587

golang & postfix - email received header is localhost

While trying to setup postfix to allow a website to sent password reset emails I've noticed that when sending emails form the command line using
echo "body" | mail -s "subject" test#example.com
the emails arrive just fine and are not marked as spam. However, when sending from withing the sites server, the header is set as being received from localhost and thus is marked as spam.
Received: from example.com (localhost [127.0.0.1])
by example.com (Postfix) with ESMTPS id CE1299C435
for <my_email#gmail.com>; Tue, 2 Aug 2016 05:28:41 +0000 (UTC)
As a note, dkim, spf and dmarc test all list as passed, so they are not the problem.
I have also tried sending an email with the same content using the above echo method and had it arrive fine (although plaintext as I used it as above and didn't add the content type headers).
Initially this was sent using smtp.SendMail
err := smtp.SendMail(hostname + ":25", nil, sender, recipients, []byte(msgstr))
which provides no way to set sending host, so in an attempt to correct this I switched to using a manual dial, sending a HELO message, then starting tls (attempting to start tls before the HELO resulted in a panic saying the HELO had to be the first call)
c, err := smtp.Dial(host + ":25")
if err != nil {
log.Panic(err)
}
if err = c.Hello(host); err != nil {
log.Panic(err)
}
if err = c.StartTLS(config.TLS()); err != nil {
log.Panic(err)
}
This still sends the email successfully, but as before the received header still shows localhost as the origin, I feel I've misunderstood something as I believed that HELO served to identify where the call was coming from.
Your advice and help is appreciated, this is the first time I've tried to configure an MTA and use it like this, there has been a bit of a learning curve that I'm evidently not over yet.
As Juergen Gmeiner suggested in the comments, my problem ended up being caused by a poorly configured /etc/hosts file, such that it wasn't effecting other services.
The existing entry was:
127.0.0.1 localhost example.com
Changing this to:
127.0.0.1 example.com localhost
solved the problem while not breaking the existing services that needed localhost to evaluate properly.
This solution worked for my locally hosted server process, if the same problem occurs with a remote server, and equivalent like would need to be created with the ip and hostname of the remote. i.e.
<remote ip> <hostname>
note: while I tested that this last part by calling from my local development build to our production server and it worked, its not a 100% tested solution.
Thank you all for your help, and I hope that this mistake on my part helps anyone else who makes a similar error in the future.

gmail for work cannot send email with SMTP

I am trying to send email to another email address..
my code run well if i am using this as my email server.
grails {
mail{
// teravin smtp setting
host = "smtp.gmail.com"
port = 465
username = "myname#gmail.com"
password = "ping123456"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.starttls.enable": "true",
"mail.smtp.socketFactory.fallback":"false"]
}
}
but i tried to using Gmail For Work like this
grails {
mail{
// teravin smtp setting
host = "smtp.gmail.com"
port = 465
username = "myname#mydomain.com" //here i am using a domain. like dwayne#alibaba.com
password = "ping123456"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.starttls.enable": "true",
"mail.smtp.socketFactory.fallback":"false"]
}
}
then i get an error like this..
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbu7
A
534-5.7.14 Armc1Kv6BMKJgBgDa5JMjBolFfZ-IxR1po773uTSasXpJcLSemxn58swxGL_3zIOhnNVF
N
534-5.7.14 5g0y20MA6FFEVrE_xzqcpS3SooMYLpr2_WWtgnNBSZi4Ycnq1SrGv-rqZ50fnOA8GPLdp
I
534-5.7.14 15howBb6bqYod_AsiKgjkfKGXK1z1F_0u79m3UmYfQXAjnai49pMz5GZkvp6oDYxEClM3
x
534-5.7.14 1CmWME6Jbkph6tVkdGd-yjlHow9c> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 f21sm1805436pfd.6 - gsm
tp
. Stacktrace follows:
Message: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt
=AKgnsbu7A
534-5.7.14 Armc1Kv6BMKJgBgDa5JMjBolFfZ-IxR1po773uTSasXpJcLSemxn58swxGL_3zIOhnNVF
N
534-5.7.14 5g0y20MA6FFEVrE_xzqcpS3SooMYLpr2_WWtgnNBSZi4Ycnq1SrGv-rqZ50fnOA8GPLdp
I
534-5.7.14 15howBb6bqYod_AsiKgjkfKGXK1z1F_0u79m3UmYfQXAjnai49pMz5GZkvp6oDYxEClM3
x
534-5.7.14 1CmWME6Jbkph6tVkdGd-yjlHow9c> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 f21sm1805436pfd.6 - gsm
tp
i wonder why i get this error...is this because i still using trial account ?
A clue to your solution lies in the error message specifically,
https://support.google.com/mail/answer/78754
Try following the "Troubleshoot" section there.
I've had this problem before and solved it using one of these steps mentioned in that page:
Sign in to your account from the web version of Gmail at
https://mail.google.com. Once you’re signed in, try signing in to the
mail app again.
Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in
with your Gmail username and password. If asked, enter the letters in
the distorted picture.

gerrit sendemail "Server rejected body"

After I configured my gerrit server with our SMTP server, I can not send email, can anyone help?
I was trying to config my gerrit with SMTP server, after I checked with command "gsasl --smtp -a --connect=10.4.103.110:25 -p passwrod", I have confirmed that my connection with SMTP server is correct.
After I configured it into gerrit.config, and restart gerrit. I tried to modify my first account's contact information by the webUI, I met a problem like "server xxxx rejected body".
Then I checked with log, and found the line is at 204 in the file "SmtpEmailSender.java", the code is like :
w = new BufferedWriter(w);
for (Map.Entry<String, EmailHeader> h : hdrs.entrySet()) {
if (!h.getValue().isEmpty()) {
w.write(h.getKey());
w.write(": ");
h.getValue().write(w);
w.write("\r\n");
}
}
w.write("\r\n");
w.write(body);
w.flush();
w.close();
if (!client.completePendingCommand()) {
throw new EmailException("Server " + smtpHost + " rejected body");
}
I resolved this problem is because I tried to display my email address as a non-relative address.
My address was aaa#mymail.com, I tried to config the user as bbb#mymail.com, the SMTP server rejected my send email request.