Skip to content

Sending a Mail

aryan edited this page May 13, 2021 · 12 revisions

Function: send_mail(email_sender: str, password: str, subject: str, message: str, email_receiver: str, hostname: str = 'smtp.gmail.com') -> None

This function is used to send emails. 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. You don't need to set the PORT.

Example: pywhatkit.send_mail("[email protected]", "password", "Test Mail", "This is a test email", "[email protected]", "smtp.gmail.com")

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 otherwise you may get an Error!

Function: 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. In background it uses the send_mail function to send the email.

Example: pywhatkit.send_hmail("[email protected]", "password", "test", "<h1>HELLO</h1>, "[email protected]")

Clone this wiki locally