def click_send_later(self): message = EmailMessage(self.sender.login, self.mailToEdit.text(), self.subjectEdit.text(), self.bodyEdit.toPlainText(), self.attachments) datetime_object = datetime.strptime(self.sendDate.text(), '%d.%m %H:%M') if datetime_object is None: self.sendStatus.setText("Bad date format. Enter %d.%m %H:%M") MailSender.save_message(message, datetime_object) self.sendStatus.setText("Saved as {0}".format(filename))
def setUp(self): self.login = good_login self.password = good_password self.credentials = ("smtp.yandex.ru", "465") self.msg_content = ("some subject", "some body") self.recipient = recipient self.sender = MailSender(self.credentials, self.login, self.password)
def test_daemon_sending(self): message = EmailMessage(self.login, self.recipient, *self.msg_content) filename = MailSender.save_message(message, datetime.now()) self.assertTrue(os.path.isfile("./" + messages_dir + "/" + filename)) format_str = "python DaemonSender.py {0} {1} {2} {3}" start_string = format_str.format(self.credentials[0], self.credentials[1], self.login, self.password) subprocess.Popen(start_string, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) self.assertFalse(os.path.isfile(filename))
def __init__(self, server_credentials: tuple, login, password): self.sender = MailSender(server_credentials, login, password) self.server_credentials = server_credentials self.login = login self.password = password self.msg_files = self._get_dates_to_files()
def test_save_message(self): message = EmailMessage(self.login, self.recipient, *self.msg_content) datetime_object = datetime.now() filename = MailSender.save_message(message, datetime_object) self.assertTrue(os.path.isfile("./" + messages_dir + "/" + filename))
def test_authorization_good(self): sender = MailSender(self.credentials, self.good_login, self.good_password) sender.sock = sender._get_connection( (self.credentials[0], int(self.credentials[1]))) self.assertEqual(sender.authorize(), True)
def test_authorization_bad(self): sender = MailSender(self.credentials, self.bad_login, self.bad_password) self.assertRaises(Exception, sender.__enter__)