Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Pure VPN - Up to 27 Months
vgp
Updated:
Today at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Python Bootcamp 100 Days of Code
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="MihiCherub" data-source="post: 26658922" data-attributes="member: 238676"><p>email module එකක් හැදුව. කට්ටිය තව improve කරල ගන්න.</p><p>[CODE=python]import smtplib</p><p>import ssl</p><p>from email import encoders</p><p>from email.mime.base import MIMEBase</p><p>from email.mime.text import MIMEText</p><p>from email.mime.multipart import MIMEMultipart</p><p></p><p>port = 465 # For SSL</p><p></p><p># Create a secure SSL context</p><p>context = ssl.create_default_context()</p><p></p><p></p><p>def send_gmail(user, password, recipients, subject, msg):</p><p> # with smtplib.SMTP("smtp.gmail.com") as connection:</p><p> with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection:</p><p> # connection.starttls()</p><p> connection.login(user=user, password=password)</p><p> connection.sendmail(from_addr=user, to_addrs=recipients,</p><p> msg=f"Subject:{subject}\n\n{msg}")</p><p></p><p></p><p>def send_gmail_rich_text(user, password, recipients, subject, text="", html=""):</p><p> message = MIMEMultipart()</p><p> message["Subject"] = subject</p><p> message["From"] = user</p><p></p><p> if isinstance(recipients, str):</p><p> message["To"] = recipients</p><p> else:</p><p> message["To"] = ", ".join(recipients)</p><p></p><p> # Turn these into plain/html MIMEText objects</p><p> text_part = MIMEText(text, "plain")</p><p> html_part = MIMEText(html, "html")</p><p></p><p> # Add HTML/plain-text parts to MIMEMultipart message</p><p> # The email client will try to render the last part first</p><p> message.attach(text_part)</p><p> message.attach(html_part)</p><p></p><p> with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection:</p><p> connection.login(user=user, password=password)</p><p> connection.sendmail(from_addr=user, to_addrs=recipients, msg=message.as_string())</p><p></p><p></p><p>def send_gmail_attachments(user, password, recipients, subject, file_name, text="", html=""):</p><p> message = MIMEMultipart()</p><p> message["Subject"] = subject</p><p> message["From"] = user</p><p> if isinstance(recipients, str):</p><p> message["To"] = recipients</p><p> message["Bcc"] = recipients # Recommended for mass emails</p><p> else:</p><p> receivers = ", ".join(recipients)</p><p> message["To"] = receivers</p><p> message["Bcc"] = receivers # Recommended for mass emails</p><p></p><p> text_part = MIMEText(text, "plain")</p><p> html_part = MIMEText(html, "html")</p><p></p><p> message.attach(text_part)</p><p> message.attach(html_part)</p><p></p><p> with open(file_name, "rb") as attachment:</p><p> # Add file as application/octet-stream</p><p> # Email client can usually download this automatically as attachment</p><p> part = MIMEBase("application", "octet-stream")</p><p> part.set_payload(attachment.read())</p><p></p><p> # Encode file in ASCII characters to send by email</p><p> encoders.encode_base64(part)</p><p></p><p> # Add header as key/value pair to attachment part</p><p> part.add_header(</p><p> "Content-Disposition",</p><p> f"attachment; filename= {file_name}",</p><p> )</p><p></p><p> # Add attachment to message</p><p> message.attach(part)</p><p></p><p> with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection:</p><p> connection.login(user=user, password=password)</p><p> connection.sendmail(from_addr=user, to_addrs=recipients, msg=message.as_string())[/CODE]</p><p></p><p>repl එක fork කරගන්න ඕන අය</p><p><a href="https://replit.com/@tharindumihi/emailhandler#email_handler.py" target="_blank">https://replit.com/@tharindumihi/emailhandler#email_handler.py</a></p></blockquote><p></p>
[QUOTE="MihiCherub, post: 26658922, member: 238676"] email module එකක් හැදුව. කට්ටිය තව improve කරල ගන්න. [CODE=python]import smtplib import ssl from email import encoders from email.mime.base import MIMEBase from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart port = 465 # For SSL # Create a secure SSL context context = ssl.create_default_context() def send_gmail(user, password, recipients, subject, msg): # with smtplib.SMTP("smtp.gmail.com") as connection: with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection: # connection.starttls() connection.login(user=user, password=password) connection.sendmail(from_addr=user, to_addrs=recipients, msg=f"Subject:{subject}\n\n{msg}") def send_gmail_rich_text(user, password, recipients, subject, text="", html=""): message = MIMEMultipart() message["Subject"] = subject message["From"] = user if isinstance(recipients, str): message["To"] = recipients else: message["To"] = ", ".join(recipients) # Turn these into plain/html MIMEText objects text_part = MIMEText(text, "plain") html_part = MIMEText(html, "html") # Add HTML/plain-text parts to MIMEMultipart message # The email client will try to render the last part first message.attach(text_part) message.attach(html_part) with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection: connection.login(user=user, password=password) connection.sendmail(from_addr=user, to_addrs=recipients, msg=message.as_string()) def send_gmail_attachments(user, password, recipients, subject, file_name, text="", html=""): message = MIMEMultipart() message["Subject"] = subject message["From"] = user if isinstance(recipients, str): message["To"] = recipients message["Bcc"] = recipients # Recommended for mass emails else: receivers = ", ".join(recipients) message["To"] = receivers message["Bcc"] = receivers # Recommended for mass emails text_part = MIMEText(text, "plain") html_part = MIMEText(html, "html") message.attach(text_part) message.attach(html_part) with open(file_name, "rb") as attachment: # Add file as application/octet-stream # Email client can usually download this automatically as attachment part = MIMEBase("application", "octet-stream") part.set_payload(attachment.read()) # Encode file in ASCII characters to send by email encoders.encode_base64(part) # Add header as key/value pair to attachment part part.add_header( "Content-Disposition", f"attachment; filename= {file_name}", ) # Add attachment to message message.attach(part) with smtplib.SMTP_SSL("smtp.gmail.com", port=port, context=context) as connection: connection.login(user=user, password=password) connection.sendmail(from_addr=user, to_addrs=recipients, msg=message.as_string())[/CODE] repl එක fork කරගන්න ඕන අය [URL]https://replit.com/@tharindumihi/emailhandler#email_handler.py[/URL] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom