Python email create - python

i can create with python outlook emails and send them. Im Using

The SenderEmailAddress property is read-only and set on received or sent emails, not composed ones.
The Outlook object model provides two main ways for sending emails from other accounts:
The MailItem.SendUsingAccount property which returns or sets an Account object that represents the account under which the MailItem is to be sent. In that case the other account should be configured in an Outlook profile as well.
The MailItem.SentOnBehalfOfName property which returns or sets a string indicating the display name for the intended sender of the mail message. In that case you need to have all the required permissions to do that on behalf of another person. Valid for Exchange only.

On a general note, no mail server (certainly not Exchange Server) will let you spoof the sender name and address (unless you were given an explicit permisison) for the obvious security reasons.
You can send on behalf of another Exchange user (if you have the permission) by setting the MailItem.SentOnBehalfOfName property. You can also create secondary Exchange / POP3/SMTP / IMAP4/SMTP accounts in Outlook and send through these accounts by setting the MailItem.SendUsingAccount property to an Account object from the Application.Session.Accounts collection.

Related

How to send promotional/mass mail in Django with Amazon SES and hide other recipients

I have surfed the internet for a day but didn't find the perfect article which gives the best practices for sending mass emails.
I have configured Amazon SES using django-ses and mails are sending correctly. Now the problem is I don't know how people send mass mail, hide other recipients, which function they use, and what pattern they follow to make sending mass mail efficient and ease.
Also, we are using templates (Django Templates) for mail and below is the best solution I got by mixin all best things I found on the internet:
# 1. Getting queryset of all recipients which will receive mail
# (mine is a little bit different but at the end, it gives queryset of all emails - not list)
subscribers = EmailNotificationSubscriber.objects.all().values_list('user__user_email', flat=True)
# 2. Opening a connection
# 3. [Looping] using `.iterator()` to fetch email one by one from queryset (I think this is to handle the cases where we have an email list of around 10k or even bigger)
# 4. Creating EmailMessage instance and sending an email using `.send()`
# Function to get HTML Message (instance of `EmailMessage`)
def get_html_msg(subject, from_email, to, template_name, ctx, connection=None):
message = get_template(os.path.join(settings.BASE_DIR, 'templates', 'email', template_name)).render(ctx)
msg = EmailMessage(subject, message, from_email, to, connection=connection)
msg.content_subtype = 'html'
return msg
# Function which sends mass mail
def send_mass_mail(subject, qs, mail_template='base.html', ctx=None, fail_silently=True, *args, **kwargs):
from_email = settings.EMAIL_FROM
with get_email_connection() as connection:
for recipient in qs.iterator():
print(f"Sending to recipient: {recipient}")
msg = get_html_msg(subject, from_email, [recipient], mail_template, ctx, connection)
msg.send(fail_silently)
Above is what I am doing:
Getting just emails and not converting it into list so I can use .iterator()
Using a single connection to sending all mails
Hiding other recipient using loop by sending mail one by one
(I will use the same template for all recipient so I will refactor that for performance later)
So, How people send mass mail with Amazon SES? Do they use something else over this? An open-source repo or example would greatly help.
Thanks so much
Edit 1: Removed Emojis
Edit 2: Question Narrowed
according to Your questions i think that firstly, when sending mass mail, You should take into account the reputation of Your SES account which can drop down massively if You decide to buy a recipients email list. In order to achive that, it is good to use Dedicated IP's in SES. Here is link to that: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/dedicated-ip.html
According to Your questions:
The best way would be to include them in bcc header, as You have set, the limit can depends on SMTP server. According to the AWS, it is 50 recipient's per message. So what You can do is You can group all of the mails and make one call with 50 recipients so it would lower Your request amount significantly.
Mass mailing has two approaches. One that, You have already tried(so one by one, and the other one which is considered better -> sending in bulks, as described above). If You would like to check something about for instance bulk sending You can see it there: https://aws.amazon.com/blogs/messaging-and-targeting/introducing-email-templates-and-bulk-sending/ Also, it is good to use only BCC field. You are ensuring Yourself, that there will not be any mistakes in displaying to the recipients email addresses of the other users.
Check that links, that I have already provided.
Yes, it is. You can easily use amazon ses templates, or create Your own ones. Also, the customization, managing Your own domains, configuration sets is really helpful and the documentation is quite good. However there are small drawbacks, and some minor bugs(for instance when You verify the domain, and it doesn't work instantly, there is a possibility that removing and adding it one more time fixes it :) ) However You have to be careful about Your reputation on SES.
Practises:
Don't use TO/CC, instead use BCC
Always monitor Your sending reputation, unless You want Your account to be blocked
Invest in dedicated ips
Block emails, which had already bounced before(Amazon has it's own suppression list, however it is much better to have one more on Your side)
Be aware of the sending quota, that You already have assigned and extend it for Your purposes
Don't buy email list
You can verify recipient's emails address existence before email sending
Be aware of the compliaints
Don't use link shorteners

Is it possible to have two mailboxes(folders) with same name?

I am working on a product where I have to interact with email servers (like zimbra, dovecot etc) through IMAP to fetch emails etc.
I am using Python's imaplib library. I connect to email server account with credentials and then select a mailbox (folder) through its name.
Now I am wondering whether is it possible to have two mailboxes with same name in an account? If yes then how to go about it ?
Question: I am probably unclear on this.
Using select(mailbox=... you are dealing with Real Folders.
Therefore no duplicate possible.
IMAP4.select(mailbox=’INBOX’, readonly=False)
Select a mailbox.
Returned data is the count of messages in mailbox (EXISTS response).
The default mailbox is 'INBOX'.
If the readonly flag is set, modifications to the mailbox are not allowed.

workaround SPAM in Catch-all email

We are building a website expecting to serve around 10k users or more.
We want a functionality that each user will have an email address # our domain, however, this email address will not be accessible by the user it will only be used to receive a very rare amount of emails (say it will be published to receive gift cards directed to that user) and we need to notify the user as any gift card is received and do something accordingly at our end
We want to use Google App Engine with Python, and what first came to our minds is that we don't actually create any real mailboxes and we create a single catch-all email that will receive any mail sent to our domain mailboxes even not existed, then we can filter all received emails and map them to our users accounts
Within current Google receive limits (1 email per second) this will work, the main issue is that SPAM mails comes and flood the catch-all mail box with emails that directly reach receive limit and email account gets suspended by Google
We want to apply a smarter solution, we only care for emails that comes from a specific sender domain (say: giftcards.com) and we can drop any other emails
Is there is any reliable service or setup at our side we can use to filter out unwanted emails and only forward emails from giftcards.com (for example) to our main Google apps email?

Choosing "From" field using python win32com outlook

I am trying to automate emails using python. Unfortunately, the network administrators at my work have blocked SMTP relay, so I cannot use that approach to send the emails (they are addressed externally).
I am therefore using win32com to automatically send these emails via outlook. This is working fine except for one thing. I want to choose the "FROM" field within my python code, but I simply cannot figure out how to do this.
Any insight would be greatly appreciated.
If you configured a separate POP3/SMTP account, set the MailItem.SendUsingAccount property to an account from the Namespace.Accounts collection.
If you are sending on behalf of an Exchange user, set the MailItem.SentOnBehalfOfName property

GAE get info (headers) on an inbound email

I'm using python 2.7 on GAE. When a user makes a request via a browser, I can get 'meta details' such as IP, browser type, request time and the user object, if they are logged in.
I have set up GAE to receive emails. What equivalent kind of 'meta details' can I retrieve from an inbound email and how do I get that information?
The InboundEmailMessage class has the most frequently used fields ready for direct access. These are:
subject
sender
to
cc
date
attachments
original
It also include original field that exposes the full meessage as a Python email.message.Message - this allows you access to all the email headers and potentially lots more.

Categories