assalamualaikum.. saya hendak bertanya tentang script python saya. script ini akan automated hantar email melalui crontab. setakat ni semua ok berjalan lancar email di hantar dari To ke Receiver [with attachment] dan tiada logs error.
saya tambah CC dalam script tetapi tidak terima email itu dan bila check dalam logs tiada error. email tetap berjalan seperti biasa cuma CC email tidak dapat email tuh.
done checking dalam spam / dalam close restriction for third party dalam gmail.
mohon otai2 programmer leh bantu newbies ni. terima kasih
method saya dah gunakan dan semua tidak terima dalam cc email >>>
method 1
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]'
cc_address = '[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Cc'] = cc_address
message['Subject'] = 'script send out latest file to email'
method 2
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]','[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'script send out latest file to email'
method 3
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = ['[email protected]','[email protected]']
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'script send out latest file to email'
di bawah script saya sekarang yang on cronjob running.
#!/usr/bin/env python3
import smtplib
import glob
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
#mail body message
mail_content = '''
this attachment contain script pyhton to send out email including attach any file with latest date and time save.
'''
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]'
cc_address = '[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['To'] = cc_address
message['Subject'] = 'script send out latest file to email'
#The subject line
#The body and the attachments for the mail
message.attach(MIMEText(mail_content, 'plain'))
list_of_files = glob.glob('/aqil/*.docx') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
attach_file_name = latest_file
attach_file = open(attach_file_name, 'rb') # Open the file as binary mode
payload = MIMEBase('application', 'octate-stream')
payload.set_payload((attach_file).read())
encoders.encode_base64(payload) #encode the attachment
#add payload header with filename
#payload.add_header('Content-Decomposition', 'attachment', filename=attach_file_name)
payload.add_header('Content-Disposition', 'attachment; filename=' + attach_file_name)
message.attach(payload)
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')
saya tambah CC dalam script tetapi tidak terima email itu dan bila check dalam logs tiada error. email tetap berjalan seperti biasa cuma CC email tidak dapat email tuh.
done checking dalam spam / dalam close restriction for third party dalam gmail.
mohon otai2 programmer leh bantu newbies ni. terima kasih
method saya dah gunakan dan semua tidak terima dalam cc email >>>
method 1
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]'
cc_address = '[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Cc'] = cc_address
message['Subject'] = 'script send out latest file to email'
method 2
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]','[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'script send out latest file to email'
method 3
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = ['[email protected]','[email protected]']
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'script send out latest file to email'
di bawah script saya sekarang yang on cronjob running.
#!/usr/bin/env python3
import smtplib
import glob
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
#mail body message
mail_content = '''
this attachment contain script pyhton to send out email including attach any file with latest date and time save.
'''
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = '12345abcd'
receiver_address = '[email protected]'
cc_address = '[email protected]'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['To'] = cc_address
message['Subject'] = 'script send out latest file to email'
#The subject line
#The body and the attachments for the mail
message.attach(MIMEText(mail_content, 'plain'))
list_of_files = glob.glob('/aqil/*.docx') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
attach_file_name = latest_file
attach_file = open(attach_file_name, 'rb') # Open the file as binary mode
payload = MIMEBase('application', 'octate-stream')
payload.set_payload((attach_file).read())
encoders.encode_base64(payload) #encode the attachment
#add payload header with filename
#payload.add_header('Content-Decomposition', 'attachment', filename=attach_file_name)
payload.add_header('Content-Disposition', 'attachment; filename=' + attach_file_name)
message.attach(payload)
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')