Sending Mail with low level python mail api (Google App Engine) - python

I need to embed images in email but GAE email api wont let me. So i need to use low level python api but i dont know how to authenticate with it. Is it possible? And if its possible simple example like sending text/plain email can be enough.
Thanks.

In GAE, with Mail API, you can embed image using message.html instead message.body.
This is the related docs email message fields

Related

Recieving emails from my website through flask?

I have an email form on my webpage where the goal is for users to be able to send my account an email. They give me their email but is there a way to send a message from their email to my email without their password. All i'm seeing online is code to send out emails through flask not recieve. What work arounds do you guys suggest where I can have users send me an email through my website.
I am pretty sure that this is not possible.
Otherwise you would have "access" on their account and could write mails to everyone you want.
A solution would be to save the message in the database and if you need it, you can send the message to you, with all the needed information, by your own mail adresse (like AKA commented).

How to add custom email headers in Google App Engine Mail API

I need help on how to add several custom email headers when sending email using GAE's Mail API (Python) i.e. Message-id, person-id and etc.
But somehow, I don't see it in the documentation: https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.mail
I can receive emails and read custom email headers using the method below:
mail_message.original.getitem('mail_header')
But I don't know how to send an email with custom email headers.
Here is the code i use to send email:
mail.send_mail(sender=sender_address,
to="handsome_me#yahoo.com",
subject="gwapo",
body="Hi")
Looks like you missed this line in the docs:
PROPERTIES = set(['body', 'amp_html', 'sender', 'to', 'cc', 'bcc', 'attachments', 'headers', 'html', 'reply_to', 'subject'])
You can provide a headers parameter containing a list of custom headers.
Looking at the sources, the headers paramenter is subject to the following restrictions:
must be a dict
all values must be strings
all keys must be ASCII
key should be in the following white list: Auto-Submitted, In-Reply-To, List-Id, List-Unsubscribe, On-Behalf-Of, References, Resent-Date, Resent-From, Resent-To.
I'm afraid you won't be able to override message-id using AppEngine as it is not in the HEADERS_WHITELIST. I forgot how crippled AppEngine is, you may want to check third-party email services. I've used mailgun and they allow arbitrary headers as long as they are prefixed by X- (just include a h:X-My-Arbitrary-Header in the payload). From the AppEngine docs:
Sending Messages with Third-Party Services
Python 2.7/3.7 |Java 8/11 |PHP 5/7 |Ruby |Go 1.9/1.11/1.12 |Node.js
Python 3.7 applications on App Engine can use third-party companies to send email, SMS messages, or make and receive phone calls. For example, you might send email to confirm business transactions, confirm the creation of user accounts, or send marketing communications.
This page lists some examples of companies that provide communication services and client libraries for Python 3.7 applications on App Engine.
Note: The services offered by these third-party companies are not covered by the App Engine Service Level Agreement.
Mailgun
Mailgun provides both RESTful APIs and client libraries for sending email. As a GCP project user, your first 30,000 messages are free every month. See the monthly pricing calculator on the sign up page for pricing on additional messages and volume discounts.
Learn more about Mailgun:
Mailgun developer documentation
Mailgun client libraries
...
SendGrid
You can use SendGrid to power your emails on App Engine. SendGrid can improve your deliverability and provide transparency into what actually happens to those emails your app sends. You can see statistics on opens, clicks, unsubscribes, spam reports and more with the SendGrid interface or its API.
App Engine customers can send 12,000 emails every month for free by signing up for the SendGrid Email API plan through the Google Cloud Platform Console. Note that Google is compensated for customers who sign up for a paid account.
Learn more about SendGrid:
SendGrid developer documentation
SendGrid client libraries
I'm not affiliated with any of those and the original page mentions other services, I'm quoting mailgun because I've used it and know it works, and sendgrid because it is mentioned by OP.
Im working on devselz.com a service which allows unlimited emails to be sent / month. It uses a P2P with private servers, where on users can use their own servers (by installing a compatct SMTP provided by devselz.)
Here are the docs: https://devselz.com/support/

how to send email with google app accounts using python smtplib?

I know how to send email by using python smtplib with normal google account. By when I try to send email with my business account, e.g. yu#mycompany.com, it doesn't work because I cannot set "less secure app access" here
https://www.google.com/settings/security/lesssecureapps
It is said “This setting is not available for Google Apps accounts.”
Any suggestions guys?
Thank you!
You can use google's 'App Passwords' feature. It means you can generate separate password for any application and use it for only this application.
This feature was invented to prevent compromising your primary password.
See answer here.
You may try this direct link if it will work for you to manage passwords.

GAE Python - Receive incoming email on #mydomain.com address

I am setting up a GAE app that triggers certain tasks by an email from the user. I've set up the app using the information on this page: https://developers.google.com/appengine/docs/python/mail/receivingmail. Everything works as expected, however, I would like to send the emails to a #mydomain.com email address, instead of a #myapp.appspotmail.com email address.
Currently I am using an automatic forward on the email address to get around this, however once this scales I expect to reach the daily limit on forwarded messages at some point (10.000 according to https://support.google.com/a/answer/166852?hl=en).
Is there any way that I can integrate my app with the #mydomain.com email address to prevent this from happening? Or would you know another solution for this issue?
Probably, you should check recently implemented GAE integration with SendGrid, I haven't used it myself (use the same solution you've described with email forwarding), but looks like it can help.
As LA_ mentioned, SendGrid offers a webhook for this. I ended up using MailGun, which has a similar functionality and calls a HTTP POST to my app whenever an email comes in on my #mydomain.com address.

AppEngine python send email api is marked as SPAM by Gmail email reader

We send email using appengine's python send_mail api.
Is there any way to tell why an email that is sent to only one recipient would be marked as SPAM. This seems to only happen when appengine's python send_mail api sends to Gmail.
In our case we are sending email as one of the administrators of our appengine application.
And the email is a confirmation letter for an order that the user just purchased, so it is definitely NOT SPAM.
Can anyone help with this?
It seems odd because it is only GMail users that seem to be reporting this issue and we are sending from appengine (All Google servers) I love Google but sometimes Google is stricter to itself than to others :)
I've added the spf TXT record to DNS such as "v=spf1 include:_spf.google.com ~all"
(I'm hoping that will help)
I've tried to add a List-Unsubscribe header to the email but it seems app engine python send mail does not support this header.
Thanks,
Ralph
My guess would be that the content of the mail looks "spammy" for Google, but you can do some things that might help you.
I would suggest you, since this is a confirmation mail, add another admin for your app an email like: do-not-reply#domain.com and use that one for the confirmation emails. Add more text to the body and include the unsubscribe links as well, so your users will have the possibility to not receive more email from your app. Maybe you wouldn't like the last part, but you have to give that options to your users, so this email won't be marked as SPAM.

Categories

Resources