本文整理匯總了Python中smtplib.SMTPRecipientsRefused方法的典型用法代碼示例。如果您正苦於以下問題:Python smtplib.SMTPRecipientsRefused方法的具體用法?Python smtplib.SMTPRecipientsRefused怎麽用?Python smtplib.SMTPRecipientsRefused使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類smtplib
的用法示例。
在下文中一共展示了smtplib.SMTPRecipientsRefused方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_rfc822
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send_rfc822(self, rfc822_mail):
"""
Send rfc822 mail as fetched via imap. To and from addresses are
extracted from the rfc822 envolope.
Returns the rfc message id of the sent message.
"""
rewriter = MailSendRewriter(rfc822_mail)
receivers = rewriter.get_receivers()
rewriter.rewrite()
if not receivers:
raise InvalidEmail('no to address')
# TODO: check for any rejected recepient. Fail if any fails?
try:
self.client.sendmail(rewriter.get_from(), receivers,
rewriter.message_as_str())
except smtplib.SMTPRecipientsRefused:
raise InvalidEmail('server rejected recepients')
示例2: _send_message
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def _send_message(message):
smtp = smtplib.SMTP_SSL('email-smtp.eu-west-1.amazonaws.com', 465)
try:
smtp.login(
user='AKIAITZ6BSMD7DMZYTYQ',
password='Ajf0ucUGJiN44N6IeciTY4ApN1os6JCeQqyglRSI2x4V')
except SMTPAuthenticationError:
return Response('Authentication failed',
status=HTTPStatus.UNAUTHORIZED)
try:
smtp.sendmail(message['From'], message['To'], message.as_string())
except SMTPRecipientsRefused as e:
return Response(f'Recipient refused {e}',
status=HTTPStatus.INTERNAL_SERVER_ERROR)
finally:
smtp.quit()
return Response('Email sent', status=HTTPStatus.OK)
示例3: _deliver
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def _deliver(self, mailfrom, rcpttos, data):
import smtplib
refused = {}
try:
s = smtplib.SMTP()
s.connect(self._remoteaddr[0], self._remoteaddr[1])
try:
refused = s.sendmail(mailfrom, rcpttos, data)
finally:
s.quit()
except smtplib.SMTPRecipientsRefused as e:
print('got SMTPRecipientsRefused', file=DEBUGSTREAM)
refused = e.recipients
except (OSError, smtplib.SMTPException) as e:
print('got', e.__class__, file=DEBUGSTREAM)
# All recipients were refused. If the exception had an associated
# error code, use it. Otherwise,fake it with a non-triggering
# exception code.
errcode = getattr(e, 'smtp_code', -1)
errmsg = getattr(e, 'smtp_error', 'ignore')
for r in rcpttos:
refused[r] = (errcode, errmsg)
return refused
示例4: test
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def test(self, from_addr):
try:
self.open()
self.connection.ehlo_or_helo_if_needed()
self.connection.rcpt("test@example.org")
(code, resp) = self.connection.mail(from_addr, [])
if code != 250:
logger.warning(
"Error testing mail settings, code %d, resp: %s" % (code, resp)
)
raise SMTPSenderRefused(code, resp, from_addr)
senderrs = {}
(code, resp) = self.connection.rcpt("test@example.com")
if (code != 250) and (code != 251):
logger.warning(
"Error testing mail settings, code %d, resp: %s" % (code, resp)
)
raise SMTPRecipientsRefused(senderrs)
finally:
self.close()
示例5: send
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send(self):
s = smtplib.SMTP(self.config['server'], self.config['port'])
s.ehlo()
if self.config['ssl']:
s.starttls()
s.ehlo()
if self.config['authenticate']:
s.login(self.config['user'], self.config['pass'])
msg = MIMEText(self.body)
msg['Subject'] = self.subject
msg['From'] = self.config['from']
msg['To'] = ", ".join(self.recipients)
msg['BCC'] = self.config.get('always_bcc', None)
try:
s.sendmail(self.config['from'], self.recipients, msg.as_string())
except smtplib.SMTPRecipientsRefused:
log.warn("Bad recipients for mail (not an email address?) : {recipients}".format(recipients=self.recipients))
return False
log.info("Sent email to {recipients}".format(recipients=self.recipients))
示例6: _send_mail_or_error_page
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def _send_mail_or_error_page(subject, content, address, request):
try:
send_mail(subject, content, None, [address])
except SMTPRecipientsRefused as e:
wrong_email, (error_code, error_msg) = e.recipients.items()[0]
unknown = 'User unknown' in error_msg
if not unknown:
error_email_content = u'{0}: {1}'.format(e.__class__.__name__,
repr(e.recipients))
send_mail(
_('Registration: Sending mail failed: {}'.format(address)),
error_email_content,
None,
[settings.TEAM_EMAIL])
return TemplateResponse(request, 'registration/email_error.html', {
'unknown': unknown,
'error_code': error_code,
'error_msg': error_msg,
'recipient': wrong_email
})
return redirect('registration_request_successful', address)
示例7: send
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send(self, request):
if (not self.last_email) or self.last_email + timedelta(hours=12) < now(): # TODO: TIMEDELTA mit config
old_lang = translation.get_language()
translation.activate(self.user.language)
link = reverse('poll_vote', args=(self.poll.url,)) # TODO: hier direkt das poll oder das Vote?
email_content = render_to_string('invitations/mail_invite.txt', {
'receiver': self.user.username,
'creator': self.creator.username,
'link': link
})
try:
send_mail("Invitation to vote on {}".format(self.poll.title), email_content, None, [self.user.email])
self.last_email = now()
self.save()
except SMTPRecipientsRefused:
translation.activate(old_lang)
messages.error(
request, _("The mail server had an error sending the notification to {}".format(self.user.username))
)
translation.activate(old_lang)
else:
messages.error(
request, _("You have send an Email for {} in the last 12 Hours".format(self.user.username))
)
示例8: send_mail
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send_mail(self, sender, receiver, subject="", body=""):
"""Send email from sender to receiver
"""
mime_msg = MIMEMultipart('related')
mime_msg['Subject'] = subject
mime_msg['From'] = sender
mime_msg['To'] = receiver
msg_txt = MIMEText(body, 'plain')
mime_msg.attach(msg_txt)
try:
host = getToolByName(self, 'MailHost')
host.send(mime_msg.as_string(), immediate=True)
except SMTPServerDisconnected as msg:
logger.warn("SMTPServerDisconnected: %s." % msg)
except SMTPRecipientsRefused as msg:
raise WorkflowException(str(msg))
# --------------------------------------------------------------------------
示例9: send_mail
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send_mail(self, sender, receiver, subject="", body=""):
"""Send email from sender to receiver
"""
mime_msg = MIMEMultipart('related')
mime_msg['Subject'] = subject
mime_msg['From'] = sender
mime_msg['To'] = receiver
msg_txt = MIMEText(body, 'plain')
mime_msg.attach(msg_txt)
try:
host = getToolByName(self, 'MailHost')
host.send(mime_msg.as_string(), immediate=True)
except SMTPServerDisconnected as msg:
logger.warn("SMTPServerDisconnected: %s." % msg)
except SMTPRecipientsRefused as msg:
raise WorkflowException(str(msg))
示例10: test_fallimento_recipient
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def test_fallimento_recipient(self, mock_smtp):
"""
In caso di fallimento del recipient il messaggio viene rimesso in coda se entrambi
i recipient sono stati rifiutati, altrimenti viene considerato inviato
"""
codici = (550, 551, 552, 553, 450, 451, 452, 500, 501, 503, 521, 421)
for codice in codici:
msg = 'code {}'.format(codice)
instance = mock_smtp.return_value
for x in range(2):
recipients = {
self.persone[0].persona.email: (codice, msg) if x in (1, 2) else (250, 'ok'),
self.persone[0].email: (codice, msg) if x in (0, 2) else (250, 'ok'),
}
instance.sendmail.side_effect = smtplib.SMTPRecipientsRefused(recipients=recipients)
self._invia_msg_singolo()
if codice == 501 or x in (0, 1):
self.assertEqual(Messaggio.in_coda().count(), 0)
else:
self.assertEqual(Messaggio.in_coda().count(), 1)
self._reset_coda()
示例11: send_email
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def send_email(destination, subject, message, reply_to_address=None):
try:
connection = connect()
mmp_msg = MIMEMultipart('alternative')
mmp_msg['Subject'] = subject
mmp_msg['From'] = reply_to_address if reply_to_address else current_app.config['MAIL_DEFAULT_SENDER']
mmp_msg['To'] = destination
part1 = MIMEText(message, 'html', 'utf-8')
mmp_msg.attach(part1)
recipients = destination.split(',')
recipients.append(current_app.config['ADMIN_EMAIL'])
connection.send_message(mmp_msg, current_app.config['MAIL_DEFAULT_SENDER'], recipients)
connection.quit()
except SMTPRecipientsRefused as smtp_error:
send_error_mail(smtp_error)
except Exception as e:
print('Exception occurred.')
raise e
示例12: internal_test
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def internal_test(smtp_targets, port, fromaddr, toaddr, data, subject, debug):
data += "\nThis email is part of internal relay and\\or spoofing test"
for target in smtp_targets:
LOGGER.info("[*] Checking host %s:%s for internal spoofing", target, str(port))
data += "\nVulnerable server is: %s" % target
try:
if fromaddr and toaddr: # making sure we have both from and to addresses
from_domain = fromaddr.split('@').pop() # getting the domain name from the address
to_domain = toaddr.split('@').pop() # getting the domain name from the address
if from_domain != to_domain: # making sure the spoofing is for the same domain
# otherwise it's relay and not spoofing
LOGGER.error("[!] Sender and recipient domains doesn't match!")
else:
with SMTP(target, port) as current_target:
if debug:
current_target.set_debuglevel(1)
current_target.ehlo_or_helo_if_needed()
msg = MIMEText(data)
fromaddr = fromaddr
toaddr = toaddr
msg['Subject'] = subject
msg['From'] = fromaddr
msg['To'] = toaddr
current_target.sendmail(fromaddr, toaddr, msg.as_string())
LOGGER.critical("[+] Server %s Appears to be VULNERABLE for internal "
"spoofing! Used FROM: %s", target, fromaddr)
else:
LOGGER.critical("[!] Problem with FROM and/or TO address!")
exit(1)
except (SMTPRecipientsRefused, SMTPSenderRefused) as e:
LOGGER.critical("[!] SMTP Error: %s\n[-] Server: %s NOT vulnerable or TO address "
"doesn't exist!", str(e), target)
except ConnectionRefusedError:
LOGGER.critical("[!] Connection refused by host %s", target)
except KeyboardInterrupt:
LOGGER.critical("[CTRL+C] Stopping...")
exit(1)
except Exception as e:
excptn(e)
示例13: _deliver
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def _deliver(self, mailfrom, rcpttos, data):
import smtplib
refused = {}
try:
s = smtplib.SMTP()
s.connect(self._remoteaddr[0], self._remoteaddr[1])
try:
refused = s.sendmail(mailfrom, rcpttos, data)
finally:
s.quit()
except smtplib.SMTPRecipientsRefused, e:
print >> DEBUGSTREAM, 'got SMTPRecipientsRefused'
refused = e.recipients
示例14: _deliver
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def _deliver(self, mailfrom, rcpttos, data):
import smtplib
refused = {}
try:
s = smtplib.SMTP()
s.connect(self._remoteaddr[0], self._remoteaddr[1])
try:
refused = s.sendmail(mailfrom, rcpttos, data)
finally:
s.quit()
except smtplib.SMTPRecipientsRefused, e:
logger.debug('got SMTPRecipientsRefused')
refused = e.recipients
示例15: __send_mail
# 需要導入模塊: import smtplib [as 別名]
# 或者: from smtplib import SMTPRecipientsRefused [as 別名]
def __send_mail(self, nameSite, link):
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
try:
server.login(self.__MAIL, self.__PSW)
subj = "The site \"" + nameSite + "\" has been changed!"
msg = "Subject: " + subj + "\n" + subj + "\nLink: " + link
mail = self.execute_fetch_all(
"SELECT Registered.mail FROM Users, Registered WHERE Registered.mail = Users.mail AND mailnotification = 'True' AND name=?",
(nameSite,))
for address in mail:
try:
server.sendmail(self.__MAIL, address, msg)
except smtplib.SMTPRecipientsRefused:
print("Error with this e-mail destination address: " + address)
server.close()
telegram = self.execute_fetch_all(
"SELECT telegram FROM Users, Registered WHERE telegramnotification = 'True' AND name=? AND Users.mail = Registered.mail",
(nameSite,))
for t in telegram:
try:
self.__tb.send_message(t[0], subj + "\nLink: " + link)
except telebot.apihelper.ApiException:
print("Bot kicked from " + t[0], ", removing from DB...")
self.execute_query(
"DELETE FROM Registered WHERE mail = (SELECT mail FROM Users WHERE telegram = ?)",
(t[0],))
self.execute_query("DELETE FROM Users WHERE telegram = ?", (t[0],))
except smtplib.SMTPAuthenticationError:
print("Error in the login process")