Best Python code snippet using autotest_python
mail.py
Source: mail.py
...15except ImportError:16 import common17from autotest.client.shared.settings import settings18DEFAULT_FROM_EMAIL = "autotest-grid@no-reply.com"19def _process_to_string(to_string):20 """21 Process a string containing email addresses. Separators: ',' ';' ':'22 :param to_string: String containing email addresses.23 :return: List with email addresses.24 """25 return [x for x in re.split('\s|,|;|:', to_string) if x]26def send(from_address, to_addresses, cc_addresses, subject, body,27 smtp_info, html=None):28 """29 Send out an email.30 Args:31 from_address: The email address to put in the "From:" field.32 to_addresses: Either a single string or an iterable of33 strings to put in the "To:" field of the email.34 cc_addresses: Either a single string of an iterable of35 strings to put in the "Cc:" field of the email.36 subject: The email subject.37 body: The body of the email. there's no special38 handling of encoding here, so it's safest to39 stick to 7-bit ASCII text.40 smtp_info: Dictionary with SMTP info.41 html: Optional HTML content of the message.42 """43 # addresses can be a tuple or a single string, so make them tuples44 if isinstance(to_addresses, str):45 to_addresses = [to_addresses]46 else:47 to_addresses = list(to_addresses)48 if isinstance(cc_addresses, str):49 cc_addresses = [cc_addresses]50 else:51 cc_addresses = list(cc_addresses)52 if html:53 message = email.mime.multipart.MIMEMultipart('alternative')54 message["To"] = ", ".join(to_addresses)55 message["Cc"] = ", ".join(cc_addresses)56 message["From"] = from_address57 message["Subject"] = subject58 message.attach(email.mime.text.MIMEText(body, 'plain'))59 message.attach(email.mime.text.MIMEText(html, 'html'))60 else:61 message = email.Message.Message()62 message["To"] = ", ".join(to_addresses)63 message["Cc"] = ", ".join(cc_addresses)64 message["From"] = from_address65 message["Subject"] = subject66 message.set_payload(body)67 if not smtp_info['port']:68 smtp_info['port'] = 2569 try:70 if smtp_info['server']:71 mailer = smtplib.SMTP(smtp_info['server'], smtp_info['port'])72 else:73 logging.info("No SMTP server specified, will try to connect to "74 "the local MTA")75 mailer = smtplib.SMTP()76 try:77 if smtp_info.get('user'):78 mailer.login(smtp_info['user'], smtp_info['password'])79 mailer.sendmail(from_address, to_addresses + cc_addresses,80 message.as_string())81 finally:82 try:83 mailer.quit()84 except:85 logging.exception('mailer.quit() failed:')86 except Exception:87 logging.exception('Sending email failed:')88class EmailNotificationManager(object):89 """90 Email notification facility, for use in things like the autotest scheduler.91 This facility can use values defined in the autotest settings92 (global_config.ini) to conveniently send notification emails to the admin93 of an autotest module.94 """95 def __init__(self, module="scheduler"):96 """97 Initialize an email notification manager.98 :param subsystem: String describing the module this manager is99 handling. Example: 'scheduler'.100 """101 self.module = module102 self.email_queue = []103 self.html_email = settings.get_value("NOTIFICATION",104 "html_notify_email",105 type=bool,106 default=False)107 self.from_email = settings.get_value("NOTIFICATION",108 "notify_email_from",109 default=DEFAULT_FROM_EMAIL)110 self.grid_admin_email = settings.get_value("NOTIFICATION",111 "grid_admin_email",112 default='')113 server = settings.get_value("EMAIL", "smtp_server", default='localhost')114 port = settings.get_value("EMAIL", "smtp_port", default=None)115 user = settings.get_value("EMAIL", "smtp_user", default=None)116 password = settings.get_value("EMAIL", "smtp_password", default=None)117 self.smtp_info = {'server': server,118 'port': port,119 'user': user,120 'password': password}121 def set_module(self, module):122 """123 Change the name of the module we're notifying for.124 """125 self.module = module126 def send(self, to_string, subject, body):127 """128 Send emails to the addresses listed in to_string.129 to_string is split into a list which can be delimited by any of:130 ';', ',', ':' or any whitespace131 """132 to_list = _process_to_string(to_string)133 if not to_list:134 return135 send(from_address=self.from_email, to_addresses=to_list, cc_addresses="",136 subject=subject, body=body, smtp_info=self.smtp_info,137 html=self.html_email)138 def send_admin(self, subject, body):139 """140 Send an email to this grid admin.141 """142 self.send(self.grid_admin_email, subject, body)143 def enqueue_admin(self, subject, message):144 """145 Enqueue an email to the test grid admin.146 """...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!