I'm writing a little script to send emails and I would like to track who opened the email with the python module pytracking like so:
import smtplib
import pytracking
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
fromaddr = "info#XXXXXXXXXX.com"
toaddr = "XXXXXXXXa#gmail.com"
msg = MIMEMultipart()
#Not sure if this is the right location for the pixel
pixel= (pixel_byte_string, mime_type) = pytracking.get_open_tracking_pixel()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "grande"
body = "bla bla bla"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('mail.XXXXXXXX.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('info#XXXXXXXX.com','XXXXXXXX')
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
print('DONE')
I read the full documentation of this module here , but I can not find from where to actually check if the pixel has been opend or which command shell I run to do so.
Can anyone advise how to check if the pixel has been opened?
Thanks
Related
The email sends and shows that it sends to both listed recipients, but only the first listed one actually receives the message. Strange since I don't notice anything particularly wrong with how I entered the addresses in (based on other examples I came across), so I'm looking for another perspective on the issue.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
email_user = 'myemail#gmail.com'
email_send = 'otheremail1#gmail.com, otheremail2#gmail.com'
subject = 'Test'
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = """Hello,
This is a test.
Thanks!"""
msg.attach(MIMEText(body,'plain'))
filename='dataset.csv'
attachment =open(filename,'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachment; filename= "+filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.office365.com',587)
server.starttls()
server.login(email_user,'password')
server.sendmail(email_user,email_send,text)
server.quit()
server.sendmail(email_user,email_send.split(','),text) and remove the space
Basically you only sent the first one and need to pass the other one.
In my implementation of smtpd.SMTPServer, I can receive messages via the process_message() callback. How could I send a reply message back to the sender?
This is a script that can send email it works for me. I don't know if is that you want but I hope its help you.
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "YOUR ADDRESS"
toaddr = "ADDRESS YOU WANT TO SEND TO"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE MAIL"
body = "YOUR MESSAGE HERE"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "YOUR PASSWORD")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
my question is whether I can send an email via python in a c++ program.
That is my actual python script.
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
# From
fromaddr = "...#gmail.com"
# To
toaddr = "..."
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
# subject
msg['Subject'] = "..."
# Text
body = "..."
msg.attach(MIMEText(body, 'plain'))
#smtplib import
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("username", "password")
text = msg.as_string()
#send email
server.sendmail(fromaddr, toaddr, text)
My plan ist it, that I will open python and import the script via the commandline in the programm.
Is there a better way to do it?
The problem is that c++ open via system("python") the commandline, but now I have to write import mail.py in the command line.
Can I do this automaticly with an other order? I will open python, import mail and quit with one order. Is that possible?
Thank You!
Here is the program for an email.
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(email, password)
smtpserver.sendmail(email, recipient, text)
print 'Message Sent!'
smtpserver.close()
The variables: email is your email address, password is the password to your email, recipient is the receiver of the email, and text is the text to send.
I HAVE A LITTLE PROBLEM.
I USE:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
msg = MIMEMultipart()
msg['From'] = 'me#gmail.com'
msg['To'] = 'you#gmail.com'
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('smtp.gmail.com',587)
# identify ourselves to smtp gmail client
mailserver.ehlo()
# secure our email with tls encryption
mailserver.starttls()
# re-identify ourselves as an encrypted connection
mailserver.ehlo()
mailserver.login('me#gmail.com', 'mypassword')
mailserver.sendmail('me#gmail.com','you#gmail.com',msg.as_string())
mailserver.quit()
AND EVERTHING IS OKAY - BUT I WOULD LIKE TO ADD A TXT FILE ATTACHMENT. CAN YOU HELP ME?
You could achieve it like this:
filename = ...
with open(filename,'r') as f:
message = MIMEText(f.read())
message.add_header('Content-Disposition', 'attachment', filename=filename)
msg.attach(message)
where msg is the MIMEMultiPart object.
I FIND ANSWER TO BUT THANKS A LOT ! :)
filename='/www/pages/DANE/komunikaty.txt'
fp=open(filename,'rb')
att = email.mime.application.MIMEApplication(fp.read(),_subtype="txt")
fp.close()
att.add_header('Content-Disposition','attachment',filename=filename)
msg.attach(att)
So I'm following a tutorial to send email in python, the problem is that it was written for python 2 not python 3(which is what I have). So here's what I'm trying to get an answer what is the module for email in python 3? the specific module I'm trying to get is is:
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex
I also have a feelling that when I get down to this module there will be an error (haven't got there yet because of
the module above giving error
import smtp
Here is the script:
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex
fromaddr = ("XXXXX#mchsi.com")
toaddr = ("XXXX#mchsi.com")
msg = MIMEMultipart
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = ("test")
body = ("This is a test sending email through python")
msg.attach(MIMEText(body, ('plain')))
import smptlib
server = smptlib.SMPT('mail.mchsi.com, 456')
server.login("XXXXX#mchsi.com", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
text = msg.as_string()
sender.sendmail(fromaddr, toaddr, text)
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
By the way here are some mistakes in your code:
fromaddr = "XXXXX#mchsi.com" # redundant parentheses
toaddr = "XXXX#mchsi.com" # redundant parentheses
msg = MIMEMultipart() # not redundant this time :)
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "test" # redundant parentheses
body = "This is a test sending email through python" # redundant parentheses
msg.attach(MIMEText(body, 'plain')) # redundant parentheses
import smtplib # SMTP! NOT SMPT!!
server = smtplib.SMTP('mail.mchsi.com', 456) # `port` is an integer
server.login("XXXXX#mchsi.com", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") # on most SMTP servers you should remove domain name(`#mchsi.com`) here
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text) # it's not `sender`