Closed hidalgo-vntu closed 4 years ago
Hey @hidalgo-vntu I think this is what you're looking for ?
import yagmail
import os
hostname = "1.1.1.1"
receiver = "john@example.com"
subject = "Server Info"
host_up = [True if os.system("ping -c 1 " + hostname) == 0 else False]
if host_up:
print(hostname, 'is up!')
contents = f'{hostname} is up!'
else:
print(hostname, 'is down!')
contents = f'{hostname} is down!'
yag = yagmail.SMTP("john@example.com", "1234-secure-pw")
yag.send(
to=receiver,
subject=subject,
contents=contents,
)
@kootenpv Suggested solution is given, you can probably close this issue and re-open if @hidalgo-vntu still needs help?
@alexpdr Thanks a lot, looks good! Indeed, feel free to reopen.
How I can with you module ping server my code:
import yagmail import os import datetime import sys import time
hostname = "server" response = os.system("ping -c 1 " + hostname)
if response == 0: body = print (hostname, 'is up!') else: text = (hostname, "is down!") receiver = "login"