how to send email with python directly from server and without smtp
When you use the mail functionality in PHP it is using the local sendmail of the host you are on, which in turn is simply a SMTP relay locally, of course locally sending emails is not really suggested as these are likely not have a good delivery rate due to DKIM, SPF and other protection mechanisms. If you care about deliverability I would recommend using either
An external SMTP server to send mail via which is correctly configured for the sending domain.
An API such as AWS SES, Mailgun, or equivalent.
If you do not care about deliverability then you can of course use local SendMail from Python, SendMail listens on the loopback address (127.0.0.1) on port 25 just like any other SMTP server, so you may use smtplib to send via SendMail without needing to use an external SMTP server.
Sending Email via Local SMTP
If you have a local SMTP server such as SendMail check it is listening as expected…
You should see it listening on the loopback address on port 25.
If its listening then you should be able to do something like this from Python to send an email.
import smtplib sender = email@example.com receivers = [firstname.lastname@example.org] message = From: No Reply <email@example.com> To: Person <firstname.lastname@example.org> Subject: Test Email This is a test e-mail message. try: smtp_obj = smtplib.SMTP(localhost) smtp_obj.sendmail(sender, receivers, message) print(Successfully sent email) except smtplib.SMTPException: print(Error: unable to send email)