search

Home  >  Q&A  >  body text

php - Linux上如何给QQ邮箱发邮件?

公司现在每天生成一些报表,要晚上发人一些员工,因为服务器不支持ssl,重新编译nginx我也不是很懂,生产机弄坏了就完了,所以没法用phpmailer来发, 听说在linux弄个mail服务器,就能通过shell发邮件,求指点

我想做的是,每天晚上6点自动,把生成的文件通过mail的附件,发给email给其他人。

阿神阿神2902 days ago522

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-10 15:12:41

    可以用python来做。
    使用smtplib模块。
    首先将报表以及需要发送的From ,To信息等编码好。具体可以查看RFC http://tools.ietf.org/html/rfc5321#section-2.3.1

    可以给你展示下我写的一个小DEMO。

    pythonimport smtplib
    
    def send_email_over_smtps(to_email,login_user,login_pwd):
        smtpserver = smtplib.SMTP("",587) #此处需要填写服务器地址,587是默认smtps端口
        smtpserver.ehlo()
        smtpserver.starttls()
        smtpserver.ehlo
        smtpserver.login(login_user, login_pwd)
        header = 'To:' + to_email + '\n' + 'From: ' + login_user + '\n' + 'Subject:testing \n'
        print header
        msg = header + '\n this is test msg from mkyong.com \n\n'
        smtpserver.sendmail(login_user, to_email, msg)
        print 'done!'
        smtpserver.close()
    
    if __name__ == "__main__":
        send_email_over_smtps('','','') 
    

    每天定时获取到文件,用crontab定时获取,然后组成邮件,发送即可。

    reply
    0
  • PHP中文网

    PHP中文网2017-04-10 15:12:41

    在机器B上做个接口,post过去用B机器发邮件。
    For the Mail functions to be available, PHP must have access to the sendmail binary on your system
    phpmailer也是用的系统函数sendmail
    你机器上用不了phpmailer,估计sendmail也是用不了的。别指望用shell发邮件了。

    reply
    0
  • Cancelreply