Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!python3
- import mailslurp_client
- import os
- """
- This Python script uses the MailSlurp service. Here's a brief explanation:
- 1. It initializes an `InboxControllerApi` object to interact with the MailSlurp API.
- 2. It retrieves a specific inbox using the provided `inbox_id`.
- 3. It extracts the email address associated with that inbox.
- The script then sends an email:
- 1. It creates an email message with a subject and body.
- 2. It connects to MailSlurp's SMTP server and logs in with your credentials.
- 3. It then sends the email.
- Note: Sending is blocked on free accounts, and trials cannot email non-mailslurp email addresses.
- """
- # Create a MailSlurp configuration
- configuration = mailslurp_client.Configuration()
- configuration.api_key['x-api-key'] = os.getenv("MAILSLURP_API_KEY")
- inbox_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
- password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
- to_address = "name@example.com"
- # Extract the email address associated with the inbox
- with mailslurp_client.ApiClient(configuration) as api_client:
- inbox_controller = mailslurp_client.InboxControllerApi(api_client)
- inbox = inbox_controller.get_inbox(inbox_id)
- my_email_address = inbox.email_address
- print("My email address:", my_email_address)
- # Send an email to the MailSlurp email address
- import smtplib
- from email.mime.text import MIMEText
- msg = MIMEText("Hello from MailSlurp!")
- msg['Subject'] = "Test email from MailSlurp"
- msg['From'] = my_email_address
- msg['To'] = to_address
- server = smtplib.SMTP('mxslurp.click', 2525)
- server.starttls()
- server.login(my_email_address, password)
- server.sendmail(to_address, my_email_address, msg.as_string())
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement