Send emails, CC + attachments, and multiple recipients in Linux

Source: Internet
Author: User

Linux has a powerful sendmail server, but such emails are often considered spam. The following code can be used to log on to your mailbox to send emails, add CC recipients, add attachments, and send emails to multiple recipients. Where:

The body of the email is in/APP/opt/Oracle/mail.txt, And/APP/opt/Oracle/report.zip is an attachment.

 

Declare <br/> pass varchar2 (20): = 'z1234 ';--???? <Br/> begin <br/> for C in (select. username from dba_users A, icaps_user B where 'Z' | B. username =. username) loop <br/> execute immediate 'alter user' | C. username | 'identified by' | pass; <br/> end loop; <br/> end; </P> <p> #! /Usr/bin/ENV python <br/> Import smtplib, mimetypes <br/> from email import encoders <br/> from email. mimebase import mimebase <br/> from email. mimetext import mimetext <br/> from email. mimemultipart import mimemultipart <br/> Import email <br/> Import time </P> <p> femail = 'xxx @ xxxx.com '<br/> temail = ['yyyyy @ yyyy.com ', 'sssss @ ssss.com '] <br/> ccmail = ['zzzzz @ zzzzz.com ', 'ggggg @ ggggg.com '] </P> <p> to_string = ''<br/> for item in temail: <br/> to_string + = item + ', '</P> <p> cc_string = ''<br/> for Item1 in ccmail: <br/> cc_string + = Item1 + ', '</P> <p> MSG = mimemultipart () <br/> MSG ['from'] = femail <br/> MSG ['to'] = to_string <br/> subject = "cash flow reports for all hotels" <br /> F = file ('/APP/opt/Oracle/mail.txt ') <br/> # If no mode is specified, 'R' EAD mode is assumed by default <br/> # While true: <br/> # line = f. readline () <br/> # If Len (line) = 0: # Zero Length indicates EOF <br/> # Break <br/> # content = line <br/> # print line, </P> <p> # notice comma to avoid automatic newline added by python <br/> content = f. read () <br/> F. close () # Close the file <br/> # print content <br/> MSG ['subobject'] = subject <br/> MSG ['reply-to'] = femail <br/> # MSG ['cc'] = cc_string <br/> MSG ['date'] = time. ctime (time. time ()) </P> <p> MSG ['x-priority '] = '''3' <br/> MSG ['x-msmail-priority'] ='' 'normal''' <br/> print content <br/> dfff = "Du-h" <br/> # Body = Email. mimetext. mimetext (''' "DD" + content "DD" ''', _ subtype = 'html', _ charset = 'utf-8') <br/> # MSG. attach (body) <br/> msgtext = mimetext (content, 'plain ', '') <br/> MSG. attach (msgtext) </P> <p> filename = R'/APP/opt/Oracle/report.zip '<br/> fp = open (filename, 'rb ') <br/> ctype, encoding = mimetypes. guess_type (filename) <br/> If ctype is none or encoding is not none: <br/> ctype = 'application/octet-stream' <br/> maintype, subtype = ctype. split ('/', 1) <br/> M = mimebase (maintype, subtype) <br/> M. set_payload (FP. read () <br/> FP. close () <br/> encoders. encode_base64 (m) <br/> m.add_header('content-disposition', 'attachment', filename='report.zip ') <br/> MSG. attach (m) </P> <p> S = smtplib. SMTP ('mail .e5systems.com ') <br/> # Sing in email with password <br/> S. login (femail, 'xxxxxxx') <br/> S. sendmail (femail, temail, MSG. as_string () <br/> Print 'mailing... '<br/> S. close ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.