Best Python code snippet using mailosaur-python_python
test_email.py
Source:test_email.py
...15##############################################################################16# FIXTURES17##############################################################################18@pytest.fixture()19def get_email(mocker):20 """Return a valid Email object."""21 config_mock = mocker.patch.object(messages.email_, 'check_config_file')22 e = Email(from_='me@here.com', to='you@there.com',23 server='smtp.gmail.com', port=465, auth='password',24 cc='someone@there.com', bcc='them@there.com',25 subject='subject', body='message', attachments=['file1', 'file2'],26 profile='myName', save=False)27 e.from_ = 'me@here.com'28 e.server = 'smtp.gmail.com'29 e.port = 46530 e.auth = 'password'31 return e32##############################################################################33# TESTS: Email.__init__...
Email.py
Source:Email.py
...8path = getpathInfo.get_Path()9report_path = os.path.join(path, 'result')10def send_mail():11 # é®ç®±çæå¡å°å12 gserver = read_conf.get_email('gserver') # ä»é
ç½®æ件ä¸è¯»åï¼é®ä»¶ä¸»é¢13 gport = int(read_conf.get_email('gport'))14 username = read_conf.get_email('username')15 password = read_conf.get_email('password')16 filename = os.path.join(report_path, "report.html")17 f = open(filename, 'rb')18 mail_body = f.read()19 f.close()20 # ç»è£
é®ä»¶å
容åæ é¢ï¼ä¸æéåæ°âutf-8âï¼ååèå符ä¸éè¦21 msg = MIMEMultipart()22 # é®ä»¶æ£æ23 msg.attach(MIMEText(mail_body, _subtype='html', _charset='utf-8'))24 # æ·»å é件25 att1 = MIMEText(open(filename, 'rb').read(), 'base64', 'utf-8')26 att1['Content-Type'] = 'application/octet-stream'27 att1["Content-Disposition"] = 'attachment; filename="%s"' % 'report.html'28 msg.attach(att1)29 msg['from'] = read_conf.get_email('mailfrom')30 msg['to'] = ','.join(read_conf.get_email('mailto').split(','))31 # æé32 msg['Cc'] = read_conf.get_email('mailcc')33 msg['Reply-To'] = read_conf.get_email('mailfrom')34 msg['Subject'] = read_conf.get_email('subject')35 try:36 smtp = smtplib.SMTP(gserver, gport)37 smtp.starttls()38 smtp.login(username, password)39 smtp.sendmail(read_conf.get_email('mailfrom'), read_conf.get_email('mailto').split(','), msg.as_string())40 smtp.quit()41 smtp.close()42 print("é®ä»¶åéæå")43 except Exception as err:44 print("Send mail failed. ", err)45if __name__ == "__main__":...
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!!