Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Solved add cc email in script python [cc email not receive but no log error]

Solved Issue

aqil_blur90

Recruit
DFM Member
Joined
Jun 4, 2021
Messages
54
Reaction score
22
DragonCoin
2,190.00
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')
 

mr jhon

Private
DFM Member
Joined
Jun 5, 2021
Messages
16
Reaction score
74
DragonCoin
4,095.00
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')
setau aku cuma ada di kat dua file nya antara file index sama fail send nya
 

w4nn4Cry

Lance Corporal
DFM Member
Joined
Jun 8, 2021
Messages
72
Reaction score
146
DragonCoin
4,040.00
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')
haa nak buat apa tuuu....ingatlah orang yang tersayang;) ? keputusan ditangan anda...anda mampu memgubahnya:LOL:
 

mr jhon

Private
DFM Member
Joined
Jun 5, 2021
Messages
16
Reaction score
74
DragonCoin
4,095.00
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')
setau aku cuma ada di kat dua file nya antara file index sama fail send
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')
macam di file index nya kita tulis macam ni

<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4_4">
<center><b>Send email to admin</b>
<br/>
<form method="post" action="kirim.php">
<?php
$ip = getenv("REMOTE_ADDR");
$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");
$hp = getenv("HTTP_X_OPERAMINI_PHONE_UA");
?>
<input type="hidden" name="ip" value="<?php echo $ip ?>" />
<input type="hidden" name="httpref" value="<?php echo $httpref ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagent ?>" />
<input type="hidden" name="hp" value="<?php echo $hp ?>" />


Name: <br />
<input type="text" name="visitor" size="15" />
<br />
Email:<br />
<input type="text" name="visitormail" size="15" />
<br />
Subject:<br />
<input type="text" name="attn" size="15">

<br />
Message:
<br />
<textarea name="notes" rows="3" cols="15"></textarea>
<br />
<input type="submit" value="Send" />
<br />
</form>
</div></div></div></div>
<div class="t1"><div class="t2"><div class="t3"><div class="t4">
 

emafazillah

Private
DFM Member
Joined
Jun 5, 2021
Messages
41
Reaction score
70
DragonCoin
3,995.00
kat script cronjob boleh try;
1) kat message['To'] = cc_address tukar message['Cc'] = cc_address
2) receiver_address kat session.sendmail tu try hard code ['[email protected]', '[email protected]']. kalau ok, maknenye utk receiver_address dalam session.sendmail receiver_address = [receiver_address] + cc_address
ada pembetulan skit... saya test modify python script seperti di bawah;

Python:
...
...
...
#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'
...
...
...
rcpt = cc_address.split(",") + [receiver_address]
session.sendmail(sender_address, rcpt, text)
...
...
 

Attachments

  • test-send-email-py.png
    test-send-email-py.png
    598.5 KB · Views: 3
Top