Skip to content

Send Mail

SigireddyBalasai edited this page Dec 4, 2022 · 1 revision
send_mail(email_sender: str, password: str, subject: str, message: str | MIMEText, email_receiver: str) -> None

This function is used to send emails. We use regex to determine the email provider using the domain in the email address and the SMTP hostname is set automatically according to the provider. The SMTP hostname is the location of the SMTP server for the email service you are using. Here is a list of the SMTP hostnames for some common email services.

Example:

import asyncio
import AsyncPywhatKit
async def main():
    await AsyncPywhatKit.send_mail("test@test.com", "password", "Test Mail", "This is a test email", "testrecv@test.com")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

The password here is the App Password that you can get from your Email Account Settings. There are various guides online on how to setup these. We recommend you to store the message in a variable if it is a long message so that the code remains readable.

Please make sure the Credentials you have entered are correct and never share you app password with anyone!


send_hmail(email_sender: str, password: str, subject: str, html_code: str, email_receiver: str) -> None

This function can be used to send emails with HTML Code as body content. It uses the send_mail function to send the email.

Example:

import asyncio
import AsyncPywhatKit
async def main():
    await AsyncPywhatKit.send_hmail("test@test.com", "password", "test", "<h1>HELLO</h1>", "receive@test.com")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Clone this wiki locally