async def rcpt(self, recipient, options=None): ''' Sends the SMTP 'rcpt' command (specifies a recipient for the message) Returns an SMTPResponse namedtuple. ''' if options is None: options = [] to = 'TO:{}'.format(quote_address(recipient)) response = await self.execute_command('RCPT', to, *options) if response.code not in status.RCPT_SUCCESS_STATUSES: raise SMTPRecipientRefused(response.code, response.message, recipient) return response
async def mail(self, sender, options=None): ''' Sends the SMTP 'mail' command (begins mail transfer session) Returns a (code, message) tuple with the server response. Raises SMTPSenderRefused if the response is not 250. ''' if options is None: options = [] from_string = "FROM:{}".format(quote_address(sender)) code, message = await self.execute_command('MAIL', from_string, *options) if code != status.SMTP_250_COMPLETED: raise SMTPSenderRefused(code, message, sender) return code, message
async def mail(self, sender, options=None): ''' Sends the SMTP 'mail' command (begins mail transfer session) Returns a (code, message) tuple with the server response. Raises SMTPSenderRefused if the response is not 250. ''' if options is None: options = [] from_string = "FROM:{}".format(quote_address(sender)) code, message = await self.execute_command( 'MAIL', from_string, *options) if code != status.SMTP_250_COMPLETED: raise SMTPSenderRefused(code, message, sender) return code, message
async def rcpt(self, recipient, options=None): ''' Sends the SMTP 'rcpt' command (specifies a recipient for the message) Returns a (code, message) tuple with the server response. ''' if options is None: options = [] to = "TO:{}".format(quote_address(recipient)) # Turn a generic STMPResponseException into SMTPRecipientRefused try: code, message = await self.execute_command('RCPT', to, *options) except SMTPResponseException as exc: raise SMTPRecipientRefused(exc.code, exc.message, recipient) success_codes = ( status.SMTP_250_COMPLETED, status.SMTP_251_WILL_FORWARD, ) if code not in success_codes: raise SMTPRecipientRefused(code, message, recipient) return code, message
async def rcpt(self, recipient, options=None): ''' Sends the SMTP 'rcpt' command (specifies a recipient for the message) Returns a (code, message) tuple with the server response. ''' if options is None: options = [] to = "TO:{}".format(quote_address(recipient)) # Turn a generic STMPResponseException into SMTPRecipientRefused try: code, message = await self.execute_command('RCPT', to, *options) except SMTPResponseException as exc: raise SMTPRecipientRefused(exc.code, exc.message, recipient) success_codes = ( status.SMTP_250_COMPLETED, status.SMTP_251_WILL_FORWARD, ) if code not in success_codes: raise SMTPRecipientRefused(code, message, recipient) return code, message
async def mail(self, sender, options=None): ''' Sends the SMTP 'mail' command (begins mail transfer session) Returns an SMTPResponse namedtuple. Raises SMTPSenderRefused if the response is not 250. ''' if options is None: options = [] from_string = 'FROM:{}'.format(quote_address(sender)) response = await self.execute_command('MAIL', from_string, *options) if response.code != status.SMTP_250_COMPLETED: try: await self.rset() except SMTPServerDisconnected: # If we're disconnected on the reset, don't raise that yet # as it's confusing pass raise SMTPSenderRefused(response.code, response.message, sender) return response