传奇广告查询第一站 同步gm1.com

python传奇自动打怪脚本_python发送邮件的脚本
原创 于2026-01-05 18:07:00发布
3 阅读
0
0

#!/usr/bin/env python

#coding=utf-8

from email.MIMEText import MIMEText

from email.MIMEMultipart import MIMEMultipart

from email.MIMEBase import MIMEBase

from email import Utils, Encoders

import mimetypes, sys,smtplib,socket,getopt

class SendMail:

def __init__(self,smtp_server,from_addr,to_addr,user,passwd):

self.mailserver=smtp_server

self.from_addr=from_addr

self.to_addr=to_addr

self.username=user

self.password=passwd

def p_w_upload(self,filename):

fd=open(filename,'rb')

filename=filename.split('/')

mimetype,mimeencoding=mimetypes.guess_type(filename[-1]) # 返回的元祖

if mimeencoding or (mimetype is None): # mimeencoding 为 True 或者 mimetype is None 执行

mimetype='application/octet-stream'

maintype,subtype=mimetype.split('/')

if maintype=='text':

retval=MIMEText(fd.read(),_subtype=subtype)

else:

retval=MIMEBase(maintype,subtype)

retval.set_payload(fd.read())

Encoders.encode_base64(retval)

retval.add_header('Content-Disposition','p_w_upload',filename=filename[-1])

fd.close()

return retval

def msginfo(self,msg,subject,filename):

# message = """Hello, ALL

#This is test message.

#--Anonymous"""

message=msg

msg=MIMEMultipart()

msg['To'] = self.to_addr

msg['From'] = self.from_addr

msg['Date'] = Utils.formatdate(localtime=1)

msg['Message-ID'] = Utils.make_msgid()

if subject:

msg['Subject'] = subject

if message:

body=MIMEText(message,_subtype='plain',_charset='utf-8')

msg.attach(body)

#for filename in sys.argv[1:]:

if filename:

msg.attach(self.p_w_upload(filename))

return msg.as_string()

def send(self,msg=None,subject=None,filename=None):

try:

s=smtplib.SMTP(self.mailserver) # 根据加密方式不同可以使用不同的代码, login登陆方式 ,未加密

'''

s=smtplib.SMTP_SSL(self.mailserver,465) # ssl 加密

s=smtplib.SMTP(self.mailserver)

s.starttls() # ttls 加密

'''

try:

s.login(self.username,self.password)

except smtplib.SMTPException,e:

print "Authentication failed:",e

sys.exit(1)

s.sendmail(self.from_addr,self.to_addr.split(','),self.msginfo(msg,subject,filename))

except (socket.gaierror,socket.error,socket.herror,smtplib.SMTPException),e:

print "*** Your message may not have been sent!"

print e

sys.exit(2)

else:

print "Message successfully sent to %d recipient(s)" %len(self.to_addr)

if __name__=='__main__':

def usage():

print """Useage:%s [-h] -s -f -t -u -p [-S -m -F ] Mandatory argum

ents to long options are mandatory for short options too.

-f, --from= Sets the name of the "from" person (i.e., the envelope sender of the mail).

-t, --to= Addressee's address. -t "test@test.com,test1@test.com".

-u, --user= Login SMTP server username.

-p, --pass= Login SMTP server password.

-S, --subject= Mail subject.

-m, --msg= Mail message.-m "msg, ......."

-F, --file= Attachment file name.

-h, --help Help documen.

"""

sys.argv[0]

sys.exit(3)

try:

options,args=getopt.getopt(sys.argv[1:],"hs:f:t:u:p:S:m:F:","--help --server= --from= --to= --user= --pass= --subject= --msg= --file=",)

except getopt.GetoptError:

usage()

sys.exit(3)

server=None

from_addr=None

to_addr=None

username=None

password=None

subject=None

filename=None

msg=None

for name,value in options:

if name in ("-h","--help"):

usage()

if name in ("-s","--server"):

server=value

if name in ("-f","--from"):

from_addr=value

if name in ("-t","--to"):

to_addr=value

if name in ("-u","--user"):

username=value

if name in ("-p","--pass"):

password=value

if name in ("-S","--subject"):

subject=value

if name in ("-m","--msg"):

msg=value

if name in ("-F","--file"):

filename=value

if server and from_addr and to_addr and username and password:

test=SendMail(server,from_addr,to_addr,username,password)

test.send(msg,subject,filename)

else:

usage()

管理员
0
0
0
分享
上一篇: php怎么实现点卡充值,利用自动发卡程序的点卡充值传奇脚本
下一篇: GM在线给玩家装备和取走玩家装备的脚本、
评论
历史记录
回顶部
浏览时间 游戏名称 游戏IP 开区网址
注册1GM论坛账号
  • 上传头像
注册

已有账号,

微信扫码登录
重置密码
重置密码

注册

绑定关联手机号
关联手机号