MCPcopy Index your code
hub / github.com/python/cpython / sendmail

Method sendmail

Lib/smtplib.py:809–911  ·  view source on GitHub ↗

This command performs an entire mail transaction. The arguments are: - from_addr : The address sending this mail. - to_addrs : A list of addresses to send this mail to. A bare string will be treated as a list with 1 address.

(self, from_addr, to_addrs, msg, mail_options=(),
                 rcpt_options=())

Source from the content-addressed store, hash-verified

807 return (resp, reply)
808
809 def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
810 rcpt_options=()):
811 """This command performs an entire mail transaction.
812
813 The arguments are:
814 - from_addr : The address sending this mail.
815 - to_addrs : A list of addresses to send this mail to. A bare
816 string will be treated as a list with 1 address.
817 - msg : The message to send.
818 - mail_options : List of ESMTP options (such as 8bitmime) for the
819 mail command.
820 - rcpt_options : List of ESMTP options (such as DSN commands) for
821 all the rcpt commands.
822
823 msg may be a string containing characters in the ASCII range, or a byte
824 string. A string is encoded to bytes using the ascii codec, and lone
825 \\r and \\n characters are converted to \\r\\n characters.
826
827 If there has been no previous EHLO or HELO command this session, this
828 method tries ESMTP EHLO first. If the server does ESMTP, message size
829 and each of the specified options will be passed to it. If EHLO
830 fails, HELO will be tried and ESMTP options suppressed.
831
832 This method will return normally if the mail is accepted for at least
833 one recipient. It returns a dictionary, with one entry for each
834 recipient that was refused. Each entry contains a tuple of the SMTP
835 error code and the accompanying error message sent by the server.
836
837 This method may raise the following exceptions:
838
839 SMTPHeloError The server didn't reply properly to
840 the helo greeting.
841 SMTPRecipientsRefused The server rejected ALL recipients
842 (no mail was sent).
843 SMTPSenderRefused The server didn't accept the from_addr.
844 SMTPDataError The server replied with an unexpected
845 error code (other than a refusal of
846 a recipient).
847 SMTPNotSupportedError The mail_options parameter includes 'SMTPUTF8'
848 but the SMTPUTF8 extension is not supported by
849 the server.
850
851 Note: the connection will be open even after an exception is raised.
852
853 Example:
854
855 >>> import smtplib
856 >>> s=smtplib.SMTP("localhost")
857 >>> tolist=["one@one.org","two@two.org","three@three.org","four@four.org"]
858 >>> msg = '''\\
859 ... From: Me@my.org
860 ... Subject: testin'...
861 ...
862 ... This is a test '''
863 >>> s.sendmail("me@my.org",tolist,msg)
864 { "three@three.org" : ( 550 ,"User unknown" ) }
865 >>> s.quit()
866

Callers 15

send_messageMethod · 0.95
testSendMethod · 0.95
testSendBinaryMethod · 0.95
testSendNullSenderMethod · 0.95

Calls 13

has_extnMethod · 0.95
mailMethod · 0.95
closeMethod · 0.95
_rsetMethod · 0.95
rcptMethod · 0.95
dataMethod · 0.95
_fix_eolsFunction · 0.85
SMTPSenderRefusedClass · 0.85
SMTPDataErrorClass · 0.85
encodeMethod · 0.45