def get_outgoing_email_account(raise_exception_not_set=True, append_to=None):
 if (not getattr(frappe.local, u'outgoing_email_account', None)):
  frappe.local.outgoing_email_account = {}
 if (not frappe.local.outgoing_email_account.get((append_to or u'default'))):
  email_account = None
  if append_to:
   email_account = _get_email_account({u'enable_outgoing': 1, u'enable_incoming': 1, u'append_to': append_to})
  if (not email_account):
   email_account = get_default_outgoing_email_account(raise_exception_not_set=raise_exception_not_set)
  if ((not email_account) and raise_exception_not_set):
   frappe.throw(_(u'Please setup default Email Account from Setup > Email > Email Account'), frappe.OutgoingEmailError)
  if email_account:
   if (email_account.enable_outgoing and (not getattr(email_account, u'from_site_config', False))):
    email_account.password = email_account.get_password()
   email_account.default_sender = email.utils.formataddr((email_account.name, email_account.get(u'email_id')))
  frappe.local.outgoing_email_account[(append_to or u'default')] = email_account
 return frappe.local.outgoing_email_account[(append_to or u'default')]

def get_outgoing_email_account ( raise_exception_not_set = True , append_to = None ) : if ( not getattr ( frappe . local , u'outgoing_email_account' , None ) ) : frappe . local . outgoing_email_account = { } if ( not frappe . local . outgoing_email_account . get ( ( append_to or u'default' ) ) ) : email_account = None if append_to : email_account = _get_email_account ( { u'enable_outgoing' : 1 , u'enable_incoming' : 1 , u'append_to' : append_to } ) if ( not email_account ) : email_account = get_default_outgoing_email_account ( raise_exception_not_set = raise_exception_not_set ) if ( ( not email_account ) and raise_exception_not_set ) : frappe . throw ( _ ( u'Please setup default Email Account from Setup > Email > Email Account' ) , frappe . OutgoingEmailError ) if email_account : if ( email_account . enable_outgoing and ( not getattr ( email_account , u'from_site_config' , False ) ) ) : email_account . password = email_account . get_password ( ) email_account . default_sender = email . utils . formataddr ( ( email_account . name , email_account . get ( u'email_id' ) ) ) frappe . local . outgoing_email_account [ ( append_to or u'default' ) ] = email_account return frappe . local . outgoing_email_account [ ( append_to or u'default' ) ]
returns outgoing email account based on append_to or the default outgoing account .