<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import smtplib <EOL> from . import base <EOL> from fluentmail . utils import sanitize_address , join_address_list <EOL> NON_ENCRYPTED = '<STR_LIT>' <EOL> SSL = '<STR_LIT>' <EOL> TLS = '<STR_LIT>' <EOL> EHLO = '<STR_LIT>' <EOL> HELO = '<STR_LIT>' <EOL> class SMTP ( base . BaseBackend ) : <EOL> def __init__ ( self , host , port = None , security = NON_ENCRYPTED , verb = EHLO , user = None , password = None ) : <EOL> self . host = host <EOL> self . security = security <EOL> self . verb = verb <EOL> self . user = user <EOL> self . password = password <EOL> self . connection = None <EOL> if port is None : <EOL> if self . security == SSL : <EOL> self . port = <NUM_LIT> <EOL> elif self . security == TLS : <EOL> self . port = <NUM_LIT> <EOL> else : <EOL> self . port = <NUM_LIT> <EOL> else : <EOL> self . port = port <EOL> def open ( self ) : <EOL> if self . connection : <EOL> return False <EOL> if self . security == TLS : <EOL> self . connection = smtplib . SMTP ( self . host , self . port ) <EOL> self . connection . starttls ( ) <EOL> elif self . security == SSL : <EOL> self . connection = smtplib . SMTP_SSL ( self . host , self . port ) <EOL> else : <EOL> self . connection = smtplib . SMTP ( self . host , self . port ) <EOL> if self . user and self . password : <EOL> self . connection . login ( self . user , self . password ) <EOL> elif self . verb == EHLO : <EOL> self . connection . ehlo ( ) <EOL> elif self . verb == HELO : <EOL> self . connection . helo ( ) <EOL> return True <EOL> def close ( self ) : <EOL> if self . connection : <EOL> self . connection . quit ( ) <EOL> self . connection = None <EOL> return True <EOL> return False <EOL> def send_multiple ( self , messages ) : <EOL> if not messages : <EOL> return <EOL> new_connection = self . open ( ) <EOL> for message in messages : <EOL> from_address = sanitize_address ( message . from_address ) <EOL> recipients = join_address_list ( message . recipients ( ) ) <EOL> self . connection . sendmail ( from_address , recipients , message . raw ( ) ) <EOL> if new_connection : <EOL> self . close ( ) </s>
