I am using python mime and I would like to implement that the receiver of the mail replies to two different mail addresses, if he clicks the "reply to" button in his mail client.
msg['To'] = receiver_email
msg['Subject'] = my_subj
msg.attach(MIMEText(my_msg, 'plain'))
msg.add_header('reply-to', reply_to)
msg.add_header('Bcc', reply_to_as_bcc)
However the reply_to_as_bcc address just receives a copy of the mail I am originally sending. How to implement that the reply_to_as_bcc address is occurring in the bcc field, if the user owning the receiver_email account is clicking reply to?
Related
I'm using python and smtplib module to send an email via SMTP server.
I create the header of the email like this, I'm using EmailMessage()
msg = EmailMessage()
msg["From"] = fromAddress
msg["To"] = toAddress
msg["Subject"] = "Hello"
msg["Delivery-Date"]
Is it possible to send an email via an SMTP server (Outlook) by specifying date and time of receipt of the email in the header of the message. With Delivery-Date, it doesn't work.
I would like to send mail notifications to my customers via python. The problem is the sender mail account needs to be hidden. Just to be clear - this is not for phishing or spamming, only personal use!
I used smtplib and setup a new 'noreply' account in gmail, but even when providing an alias to the message, the 'mail from:' header contains my actual mail.
import smtplib
from email.mime.text import MIMEText
from email.utils import *
email_sender = 'noreply%%#gmail.com'
email_receiver = 'example%%%#gmail.com'
subject = 'Python!'
msg = MIMEText('This is the body of the message.')
msg['To'] = formataddr(('Recipient', 'example%%%#gmail.com'))
msg['From'] = formataddr(('Author', 'author#example.com'))
msg['Subject'] = 'Simple test message'
connection = smtplib.SMTP('smtp.gmail.com', 587)
connection.starttls()
connection.login(email_sender, 'password')
connection.sendmail(msg['From'], email_receiver, msg.as_string())
connection.quit()
I get the mail in to my inbox as expected but when clicking 'more details' the original sender address appears.
The first argument to sendmail is the envelope sender, and should be just the email terminus, not a formatted address; so passing in msg['From'] there is doubly wrong (one, because you don't want to show it; and two, because you are passing in the entire From: header with display name and all).
I want to send email in python and the following code works. However I want to send the email as a google group. Since a google group has no password, I am not able to login to the server. Is there anyway I can go about this?
def sendEmail(self, toEmail, subject, message ):
msg = MIMEMultipart()
password = "*****"
msg['From'] = "abc#gmail.com"
msg['To'] = toEmail
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'],password)
server.sendmail(msg['From'], msg['To'].split(","), msg.as_string())
server.quit()
logging.debug('sent email to %s', (msg['To']))
It sends like you should use a Service Account to send the email on your behalf.
Here is a pretty good guide (not written by me): https://medium.com/lyfepedia/sending-emails-with-gmail-api-and-python-49474e32c81f
Hello I am fairly new to python and stumbled upon this cool feauture that with only a few lines of code, python can send emails.
I am currently not sure if the code that I have below works or if its something on my end? Since I am totally new to this I have no way to test if I am on the right track or not.
When running the code, it compiles with no problem but I never receive the messages.
Also, I am sending emails to myself, so I should see them rather quickly.
Here is my Outlook code:
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'myemail#hotmail.com'
mail.Subject = 'Hello this is you!
mail.Body = 'Hello!!!!!!'
mail.HTMLBody = '<h2>This is an H2 message</h2>' #this field is optional
# To attach a file to the email (optional):
attachment = "C:/Users/OneDrive/Documents/Desktop/Social_Network_Ads.csv"
mail.Attachments.Add(attachment)
mail.Send()
Here is my Gmail Code:
import smtplib
fromaddr = 'myemail#gmail.com'
toaddrs = 'myemail#gmail.com'
msg = 'There was a terrible error that occured and I wanted you to know!'
# Credentials (if needed)
username = '###username###'
password = '###password###'
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
Please let me know why I am not receiving the email or why its showing as not sent?
EDIT:
I am connected to my local hotmail account and I am logged into Gmail, so I am hopping its not a connection issue.
When I go to check my sent folder nothing seems to have been sent
I've made a little Python script that sends emails using smtplib.
For example, I have an email that needs to be sent to n users (via To: field), but I also need to send this email to m other users, via Cc: field.
Obviously those n + m email addresses are from different domains (#mydomain, #gmail, #hotmail, #whatever). The emails are correctly delivered to each address if I put the email addresses in the To: field, but the same thing doesn't happen if I put the emails in the Cc: field....
For example
FROM: me#mydomain.com
TO: alice#mydomain.com, bob#gmail.com, mallory#hotmail.com
CC: john#mydomain.com, robert#yahoo.com, clara#gmail.com
note that the email is sent using a #mydomain.com account. The addresses in the TO: list correctly receive the email, while only john#mydomain.com, from the CC: list, get the email..
It seems that the CC field works only with same-domain-email... Any idea?
Anyway, this is the code:
msg = MIMEText(mailContent)
msg["Subject"] = "This is the subject"
msg["From"] = "me#mydomain.com"
toEmails = ["alice#mydomain.com", "bob#gmail.com", "mallory#hotmail.com"]
ccEmails = ["john#mydomain.com", "robert#yahoo.com", "clara#gmail.com"]
msg["To"] = ",".join(toEmails)
msg["Cc"] = ",".join(ccEmails)
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("me#mydomain.com", "password")
server.sendmail("me#mydomain.com", toEmails, msg.as_string())
server.quit()
Thanks
change this line
server.sendmail("me#mydomain.com", toEmails+ccEmails, msg.as_string())