Unable to send emails from my app via gmail account

Hello,

I used to send emails with my app using my gmail login data but for a few days now it is not making the connections and I am no longer able to send emails via my app.

I have “Access for less secure apps” turned on.

Should I be using “Google 2-Step Verification”?

What could be the problem and how can I fix it?

Thanks.

Lennox

I have been in the same boat with new accounts I created. It seems Google has some issues with them.

Thanks Michel, so I won’t be able to send emails from my app using my gmail login/password again?

Is there an alternative?

Lennox

I have deployed apps that do that all the time, but 2 step authentication is not turned on for the gmail account I send through.

Maybe you need to set up an App password:

https://support.google.com/accounts/answer/185833?hl=en

Thanks Karen,

That works, well at least it worked this time.
I’ll try it out a few more times tomorrow and if it works I’ll check it as “This answers my question”

Thanks again.

Lennox

Hi Karen,

I tried it a few times last night and it worked. It was the 2 step authentication that I used.

Today now at a different location with a different ISP it is not working. I use the same Mac Mini at both locations. Nothing else has changed.

Does this have anything to do with the ISP? Do I have to create a different 2 step authentication?

Thanks.

Lennox

I never tried using it… they threatened too turn on 2 step authentication at work (which would have killed an important app of mine) so I looked into it a little bit… But they never turned it on so i never actually tried it.

  • Karen

Thanks Karen,

It works at home but not at the office, I think it may be the ISP that I have at the office is the problem.

Thanks again.

Lennox

There’s also free smtp services with an HTTP api you can try if your ISP prevents you from sending emails.

Hi Albin,

Can you give the names of a few so thai I can try them?

Thanks.

Lennox

Try mailjet.com - Though they don’t seem to be free any longer but I’m sure there are others :slight_smile:

Edit: Still seems to be free for 200 e-mails/month. http://dev.mailjet.com (Scroll down to the bottom)
http://dev.mailjet.com/guides/#make-your-first-request
You should be able to use the HTTPSecureSocket or curl in a shell.

(Sorry, my last post didn’t give you any further info. I was in a hurry :))

Sendgrid has 200/day and 12.000/month free. Mandrill also has a free plan. Setting up Sendgrid takes about 5 minutes. There should be code around for using Mandrill in Xojo (search the forum).

Mailjet also is 200/DAY.

Thanks for the correction :slight_smile:

Thanks Beatrix and Albin, I have signed up with Sendgrid and they are finished provisioning my account. I am all set to begin sending email.

I am looking at the “Important Next Steps” now, quite a lot to stuff.

While I am digesting all that stuff, how do I send an email with Sendgrid,? - ( I need a jump-start).

Thanks.

Lennox

Sending mails is quite simple. Add a secure SMTP socket to the window and then in a button or similar add some code:

[code]// set up the socket
Socket1.Secure = True
Socket1.ConnectionType = SMTPSecureSocket.TLSv1
Socket1.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
socket1.address = “smtp.sendgrid.net
socket1.port = 465
socket1.username = app.GetMore
socket1.Password = app.GetSocket
if socket1.Username = “” or Socket1.Password = “” then
globals.theErrorLog.DialogErrorProceed kErrorUserNameMissing
Return
end if

// populate the email message to company
dim MailToCompany as new emailMessage
MailToCompany.fromAddress = TFName.Text + " <"+ TFEmailAddress.Text.Trim + “>”
MailToCompany.subject = “Error Report”

MailToCompany.bodyPlainText = “xxx”
MailToCompany.BodyHTML = “yyy”
MailToCompany.headers.appendHeader “X-Mailer”, Globals.Company

// add recipients
dim CompanyEmail as String = app.GetOther
if CompanyEmail <> “” then
MailToCompany.AddRecipient CompanyEmail
else
globals.theErrorLog.DialogErrorProceed Replace(kErrorEmailMissing, “<>”, Globals.Company)
Return
end if

'show that mail is being sent
LMailBeingSent.Text = kMailSend
ProgressWheel1.Visible = true
me.Enabled = False
PBCancel.Enabled = True

// send the emails
socket1.messages.append MailToCompany
socket1.sendMail[/code]

Thanks Beatrix for an extremely quick response with code!!!

I will set it up accordingly.

Thanks again.

Lennox

Hi Beatrix,

I’ve been trying it out without success.
I have a few questions…

SendgridMailSocket.username = is this the username that I created with Sendgrid
SendgridMailSocket.Password = is this the password that I created with Sendgrid

Is Sendgrid forwarding my emails via my Google account?
I had created an app password and 2-Step Verification with Google should I cancel them?

Thanks.

Lennox

[quote=275171:@Lennox Jacob]Is Sendgrid forwarding my emails via my Google account?
I had created an app password and 2-Step Verification with Google should I cancel them?[/quote]
Your google e-mail has nothing to do with using another mail service, that’s kind of the point :wink:

Hi Beatrix,

I’ve been using a modified version of your code above, this is what I have…

// set up the socket
SendgridMailSocket.Secure = True
SendgridMailSocket.ConnectionType = SMTPSecureSocket.TLSv1
SendgridMailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
SendgridMailSocket.address = “smtp.sendgrid.net
SendgridMailSocket.port = 465
SendgridMailSocket.username = “MySendgridUsername” //app.GetMore
SendgridMailSocket.Password = “MySendgridPassword” //app.GetSocket
'if SendgridMailSocket.Username = “” or SendgridMailSocket.Password = “” then
'globals.theErrorLog.DialogErrorProceed kErrorUserNameMissing
'Return
'end if

// populate the email message to company
dim MailToCompany as new emailMessage
MailToCompany.fromAddress = SendersEmailAddressTF.Text.Trim
MailToCompany.subject = EmailSubjectTF.Text

MailToCompany.bodyPlainText = eMailMessageTF.Text //“xxx”
MailToCompany.BodyHTML = “yyy”
MailToCompany.headers.appendHeader “X-Mailer”, “Pony SMTP Demo” //'MailToCompany.headers.appendHeader “X-Mailer”, Globals.Company

'show that mail is being sent
StatusText.Text = “Sending” //kMailSend // LMailBeingSent.Text = kMailSend
ProgressWheel1.Visible = true
me.Enabled = False

// send the emails
SendgridMailSocket.messages.append MailToCompany
SendgridMailSocket.sendMail

I did not see where the recipient address should be.

Am I missing something?

Thanks.

Lennox

OK Thanks,

I got it now.
SendgridMailSocket.username = MySendgridUsername
SendgridMailSocket.Password = MySendgridPassword

Lennox