-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from nishant4500/patch-11
Create test email.py
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import smtplib | ||
|
||
def send_email(subject, body, to_email): | ||
try: | ||
|
||
smtp_server = 'sandbox.smtp.mailtrap.io' | ||
smtp_port = 2525 # Provided by Mailtrap | ||
sender_email = 'yourusername' # Use Mailtrap's provided username | ||
send_password = 'yourpassword' # Use Mailtrap's provided password | ||
|
||
message = f'Subject: {subject}\n\n{body}' | ||
|
||
with smtplib.SMTP(smtp_server, smtp_port) as server: | ||
server.starttls() | ||
server.login(sender_email, send_password) | ||
server.sendmail(sender_email, to_email, message) | ||
|
||
print(f"Email sent to {to_email}") | ||
|
||
except Exception as e: | ||
print(f"Something went wrong: {e}") | ||
|
||
if __name__ == "__main__": | ||
send_email("Test Email", "This is a test email body", "[email protected]") |