How to use sendmail method in autotest

Best Python code snippet using autotest_python

mail_stub.py

Source:mail_stub.py Github

copy

Full Screen

...160 smtp.ehlo()161 if self._smtp_user:162 smtp.login(self._smtp_user, self._smtp_password)163 tos = [mime_message[to] for to in ['To', 'Cc', 'Bcc'] if mime_message[to]]164 smtp.sendmail(mime_message['From'], tos, mime_message.as_string())165 finally:166 smtp.quit()167 def _SendSendmail(self, mime_message,168 popen=subprocess.Popen,169 sendmail_command='sendmail'):170 """Send MIME message via sendmail, if exists on computer.171 Attempts to send email via sendmail. Any IO failure, including172 the program not being found is ignored.173 Args:174 mime_message: MimeMessage to send. Create using ToMIMEMessage.175 popen: popen function to create a new sub-process.176 """177 try:178 tos = []...

Full Screen

Full Screen

test_sendmail.py

Source:test_sendmail.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 MoinMoin - MoinMoin.mail.sendmail Tests4 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>5 @license: GNU GPL, see COPYING for details.6"""7from email.charset import Charset, QP8from email.header import Header9from MoinMoin.mail import sendmail10from MoinMoin import config11class TestdecodeSpamSafeEmail:12 """mail.sendmail: testing mail"""13 _tests = (14 ('', ''),15 ('AT', '@'),16 ('DOT', '.'),17 ('DASH', '-'),18 ('CAPS', ''),19 ('Mixed', 'Mixed'),20 ('lower', 'lower'),21 ('Firstname DOT Lastname AT example DOT net',22 'Firstname.Lastname@example.net'),23 ('Firstname . Lastname AT exa mp le DOT n e t',24 'Firstname.Lastname@example.net'),25 ('Firstname I DONT WANT SPAM . Lastname@example DOT net',26 'Firstname.Lastname@example.net'),27 ('First name I Lastname DONT AT WANT SPAM example DOT n e t',28 'FirstnameLastname@example.net'),29 ('first.last@example.com', 'first.last@example.com'),30 ('first . last @ example . com', 'first.last@example.com'),31 )32 def testDecodeSpamSafeMail(self):33 """mail.sendmail: decoding spam safe mail"""34 for coded, expected in self._tests:35 assert sendmail.decodeSpamSafeEmail(coded) == expected36class TestencodeSpamSafeEmail:37 """mail.sendmail: testing spam safe mail"""38 _tests = (39 ('', ''),40 ('@', ' AT '),41 ('.', ' DOT '),42 ('-', ' DASH '),43 ('lower', 'lower'),44 ('Firstname.Lastname@example.net',45 'firstname DOT lastname AT example DOT net'),46 ('F.Lastname@example.net',47 'f DOT lastname AT example DOT net'),48 )49 def testEncodeSpamSafeMail(self):50 """mail.sendmail: encoding mail address to spam safe mail"""51 for coded, expected in self._tests:52 assert sendmail.encodeSpamSafeEmail(coded) == expected53 def testEncodeSpamSafeMailAndObfuscate(self):54 """mail.sendmail: encoding mail address by an obfuscate string to spam safe mail """55 for coded, expected in self._tests:56 expected = expected.replace(' AT ', ' AT SYCTE ')57 assert sendmail.encodeSpamSafeEmail(coded, 'SYCTE') == expected58class TestEncodeAddress:59 """ Address encoding tests60 See http://www.faqs.org/rfcs/rfc2822.html section 3.4.61 Address Specification.62 mailbox = name-addr / addr-spec63 name-addr = [display-name] angle-addr64 angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr65 """66 charset = Charset(config.charset)67 charset.header_encoding = QP68 charset.body_encoding = QP69 def testSimpleAddress(self):70 """ mail.sendmail: encode simple address: local@domain """71 address = u'local@domain'72 expected = address.encode(config.charset)73 assert sendmail.encodeAddress(address, self.charset) == expected74 def testComposite(self):75 """ mail.sendmail: encode address: 'Phrase <local@domain>' """76 address = u'Phrase <local@domain>'77 expected = str(address)78 assert sendmail.encodeAddress(address, self.charset) == expected79 def testCompositeUnicode(self):80 """ mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """81 address = u'ויקי <local@domain>'82 phrase = str(Header(u'ויקי'.encode('utf-8'), self.charset))83 expected = phrase + ' ' + '<local@domain>'84 assert sendmail.encodeAddress(address, self.charset) == expected85 def testEmptyPhrase(self):86 """ mail.sendmail: encode address with empty phrase: '<local@domain>' """87 address = u'<local@domain>'88 expected = 'local@domain'89 assert sendmail.encodeAddress(address, self.charset) == expected90 def testEmptyAddress(self):91 """ mail.sendmail: encode address with empty address: 'Phrase <>'92 Let the smtp server handle this. We may raise error in such93 case, but we don't do error checking for mail addresses.94 """95 address = u'Phrase <>'96 expected = str(address)97 assert sendmail.encodeAddress(address, self.charset) == expected98 def testInvalidAddress(self):99 """ mail.sendmail: encode invalid address 'Phrase <blah'100 Assume that this is a simple address. This address will101 probably cause an error when trying to send mail. Junk in, junk102 out.103 """104 address = u'Phrase <blah'105 expected = str(address)106 assert sendmail.encodeAddress(address, self.charset) == expected...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful