2

VBS自动随机发送邮件脚本—By:晴云孤魂

Posted by 晴云孤魂 on 2011 年 02 月 14 日 in windows Script Design |

‘————————————
‘生成随机邮箱代码模块开始
Function get_roundmail()
Dim all_mail,all_letter,all_number,round_mail,round_letter,round_number,letter_length,number_length,temp_data,to_email,confirm_email,exit_flag
confirm_email=””
exit_flag=false
letter_length=0
temp_data=””
all_mail=array(“qq.com”,”163.com”,”126.com”,”sohu.com”,”sina.com”,”sina.cn”,”yahoo.cn”)
all_letter=array(“q”,”w”,”e”,”r”,”t”,”y”,”u”,”i”,”o”,”p”,”a”,”s”,”d”,”f”,”g”,”h”,”j”,”k”,”l”,”z”,”x”,”c”,”v”,”b”,”n”,”m”,”_”) ‘定义字母及下划线数组
all_number=array(0,1,2,3,4,5,6,7,8,9)

Randomize  ‘获取随机邮箱服务器
round_mail=fix(rnd()*6)
to_email=all_mail(round_mail)

IF to_email<>”qq.com” Then

Do ‘随机字母长度
Randomize
letter_length=fix(rnd()*8)
If letter_length>=3 and letter_length<=8 Then
Exit Do
End if
loop

Do ‘随机数字长度
Randomize
number_length=fix(rnd()*8)
If number_length>=5 and number_length<=8 Then
Exit Do
End if
loop

Else

Do ‘随机QQ号码长度
Randomize
number_length=fix(rnd()*11)
If number_length>=5 and number_length<=10 Then
Exit Do
End if
loop

End IF
If letter_length<>0 Then
For i=0 to letter_length    ‘生成随机字母并累加至邮箱用户名
  exit_flag=false
 do while(exit_flag=false)
Randomize
round_letter=fix(rnd()*27)
If temp_data<>all_letter(round_letter) Then
     exit_flag=true
   End if
 loop
temp_data=all_letter(round_letter)
confirm_email=confirm_email&temp_data
Next
End If

For k=0 to number_length    ‘生成随机数字并累加至邮箱用户名
  exit_flag=false
 do while(exit_flag=false)
  Randomize
  round_number=fix(rnd()*10)
   If temp_data<>all_number(round_number) Then
     exit_flag=true
   End if
 loop
temp_data=all_number(round_number)
confirm_email=confirm_email&temp_data
Next

get_roundmail=confirm_email&”@”&to_email
End Function
‘生成随机邮箱代码模块结束
‘———————————–

‘————————————
‘读取外部配置文件模块开始
Dim SmtpServer,Username,Password,MainSubject,Mailbody,Sendmodel,Fortomail
Sub read_inifile()
Dim inifile,readtxt
Set doit=Createobject(“scripting.filesystemobject”)
Set inifile=doit.opentextfile(“mail_setinfo.ini”,1)
For n=1 to 5
inifile.skipline()
Next
readtxt=inifile.readline()
if instr(readtxt,”SmtpServer=”)=1 Then SmtpServer=right(readtxt,len(readtxt)-len(“SmtpServer=”))
readtxt=inifile.readline()
if instr(readtxt,”Username=”)=1 Then Username=right(readtxt,len(readtxt)-len(“Username=”))
readtxt=inifile.readline()
if instr(readtxt,”Password=”)=1 Then Password=right(readtxt,len(readtxt)-len(“Password=”))
readtxt=inifile.readline()
if instr(readtxt,”MainSubject=”)=1 Then MainSubject=right(readtxt,len(readtxt)-len(“MainSubject=”))
readtxt=inifile.readline()
if instr(readtxt,”Mailbody=”)=1 Then Mailbody=right(readtxt,len(readtxt)-len(“Mailbody=”))
readtxt=inifile.readline()
if instr(readtxt,”Sendmodel=”)=1 Then Sendmodel=right(readtxt,len(readtxt)-len(“Sendmodel=”))
readtxt=inifile.readline()
if instr(readtxt,”Fortomail=”)=1 Then Fortomail=right(readtxt,len(readtxt)-len(“Fortomail=”))
inifile.close()
Set doit=nothing
End Sub
‘读取外部配置文件模块结束
‘————————————-

‘————————————-
‘发送邮件构造函数
Function Send_email(Username,Password,SmtpServer,MainSubject,Htmlcontent,Forwardmail)
On Error Resume Next
NameSpace = “http://schemas.microsoft.com/cdo/configuration/
Set Email = createObject(“CDO.Message”)
Email.From = Username
Email.To = Forwardmail
Email.Subject = MainSubject
Email.Htmlbody = Htmlcontent

With Email.Configuration.Fields
.Item(NameSpace&”sendusing”) = 2
.Item(NameSpace&”smtpserver”) = SmtpServer
.Item(NameSpace&”smtpserverport”) = 25
.Item(NameSpace&”smtpauthenticate”) = 1
.Item(NameSpace&”sendusername”) = Username
.Item(NameSpace&”sendpassword”) = Password
.update
End With

Send_email=Email.Send()
End Function

‘———————————————

‘———————————————
‘主程序引导代码

call read_inifile()
Msgbox Sendmodel
IF Mailbody<>”” Then
Set fso=Createobject(“scripting.filesystemobject”)
If Not fso.fileexists(Mailbody) Then
Msgbox “未找到指定的邮件文件!”,16,”错误”
wscript.quit
End If
Set this_mail=fso.opentextfile(Mailbody,1)
Htmlcontent=this_mail.readall()
this_mail.close()
Else
Msgbox “邮件内容未配置!”,16,”错误”
End if
If Sendmodel=1 then Forwardmail=get_roundmail()
If Sendmodel=2 then Forwardmail=Fortomail
msgbox Htmlcontent
isok=Send_email(Username,Password,SmtpServer,MainSubject,Htmlcontent,Forwardmail)
if isok=”” then msgbox “发送成功!”

2 Comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注

使用腾讯微博登陆

Copyright © 2011-2017 晴云孤魂's Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.2.2, from BuyNowShop.com.

普人特福的博客cnzz&51la for wordpress,cnzz for wordpress,51la for wordpress