The method and code _vbs of the VBS sending mail regularly

Source: Internet
Author: User
' Use VBS to write a script, and then use the Windows platform under the scheduled task to call, a regular mass mail every day.
' Code as follows: Download address Http://www.51tiao.com/info.vbs
Copy Code code as follows:

Dim Connstr,conn
Dim sql,rs,msg

Sub opendb ()
ConnStr = "Dsn=51tiao." Com; Uid=sa; pwd=; "
If not IsObject (Conn) Then
Set conn = CreateObject ("Adodb.connection")
Conn.Open ConnStr
End If
End Sub

OPENDB ()
Send ()
Closedb ()

Sub Send ()
On Error Resume Next ' Error continued execution
' Message content
msg = "& "<meta name=" "Author" "content=" "Breeze, qq:110125707, msn:anwellsz@msn.com" ">" &vbcrlf _
& "<style type= ' text/css ' >" &vbcrlf _
& "<!--" &vbcrlf _
& "Td,form,select,input,p,table,.font {font-size:12px;line-height:20px}" &vbcrlf _
& "A:link {color: #000000; font-size:12px; Text-decoration:none} "&vbcrlf _
& "a:visited {color: #000000; font-size:12px; Text-decoration:none}" &vbcrlf _
& "A:hover {color: #ff7f2c; font-size:12px; Text-decoration:underline}" &vbcrlf _
& "-->" &vbcrlf _
& "</style>" &vbcrlf _
& "& "<table width=640>" &vbcrlf _
& "&LT;TR&GT;&LT;TD align=right> recommended Today" &year (Date ()) & "Year" &month (Date ()) & "Month" &day (date () ) & "Day <a href=" "http://www.51tiao.com" "target=" "_blank" "><font size=3><b> Shanghai Flea Market </b> </font></a> </td></tr></table></div></td></tr></table> " &vbcrlf _
& "<table width=640>" &vbcrlf _
& "<tr bgcolor= ' #FF9D5C ' ><td height=3></td></tr><tr><td> </td></ Tr><tr> "&vbcrlf _
& "<td>" &vbcrlf _
& "<ul>" &vbcrlf _
& "<p>"
sql = "SELECT distinct a.infoid,a.strtitle from Newinfoarticle a" _
& "INNER join Newinfoprop B" _
& "On a.infoid = b.infoid and A.intgood = 1 and A.intshenhe = 1 and b.rid1 = 908 and DateDiff (D,createtime,getdate ()) =0 "_
& "ORDER BY a.infoid Desc"
Set rs = conn.execute (SQL)
If rs.eof Then
WScript.Echo "No record!"
Rs.close:Set rs = Nothing
Exit Sub
End If
Do as not rs.eof
msg = msg& "★<a href=" "http://www.51tiao.com/4/Show.asp?ID=" &rs ("Infoid") & "" "title =" "&rs (" Strtitle ") &" "target=" "_blank" ">" _
&rs ("Strtitle") & "</a><br>" &vbcrlf
Rs.movenext
Loop
Rs.close:set rs=nothing
msg = msg & "</ul></p>" &vbcrlf _
& "</td>" &vbcrlf _
& </tr><tr><td> </td></tr><tr bgcolor= ' #FF9D5C ' ><td height=3></ Td></tr> "&vbcrlf _
& "<tr align=right><td><a href=" "http://www.51tiao.com" "target=" "_blank" "><font face=" Arial Black ' size=3>51tiao.com</font></a> </td></tr> ' &vbcrlf _
& "</table><p></p></body>
' Get email address
Dim I,total,jmail
i = 1
Dim BadMail ' don't receive mailing list format ' email address ', ' email address '
BadMail = "' 123@163.com ', ' 122@126.com '"
sql = "SELECT distinct b.stremail from UserInfo a inner join Userinfo_1 B" _
& "On a.id = B.intuserid and B.stremail <>" and (Charindex (' 3 ', a.struserlevel) >0 or charindex (' 4 ', a.struser Level) >0) "_
& "and B.stremail Not in (" &BadMail& ")" _
& "ORDER by B.stremail"
Set rs = CreateObject ("Adodb.recordset")
Rs.Open sql,conn,1,1
Total = Rs.recordcount
If rs.eof Then
WScript.Echo "No Users!"
Rs.close:Set rs = Nothing
Exit Sub
End If

' Send once per 20 mail addresses
For i = 1 to Total
If I Mod = 1 Then
Set JMail = CreateObject ("JMail. Message ")" To create an object to send mail
' Jmail.silent = True ' Mask exception error, return False to true two value
JMail. Logging = True ' Log
JMail. Charset = "GB2312" ' Text Encoding for messages
JMail. ContentType = "text/html" The format of the message is HTML format or plain text
End If
JMail. AddRecipient RS (0)
If I Mod = 0 Or i = 665 Then
JMail. from = "info at 51tiao" ' E-mail address of sender
JMail. FromName = "Shanghai Flea Market" ' The name of the sender
JMail. Mailserverusername = "Info" Login to mail server username (your email address)
JMail. Mailserverpassword = "123123" ' Login to mail server password (your mail password)
JMail. Subject = "Shanghai Flea Market Today recommended" &year (date ()) & "Year" &month (Date ()) & "Month" &day (date ()) & "Day" ' Mail title
JMail. The contents of the BODY = MSG ' message
JMail. Priority = 3 ' Mail Emergency program, 1 for fastest, 5 for slowest, 3 for default value
JMail. Send ("mail.51tiao.com") ' Perform mail delivery (via mail server address)
JMail. Close ()
Set JMail = Nothing
End If
Rs.movenext
Next
Rs.close:Set rs = Nothing

' Log in C:\jmail month/day. txt
Const def_fsostring = "Scripting.FileSystemObject"
Dim Fso,txt
Set fso = CreateObject (def_fsostring)
Set Txt=fso. CreateTextFile ("C:\jmail" &datevalue (Date ()) & ". txt", true)
Txt. Write "The message was sent successfully and a total of" &total& "mail was sent, sent to" &now () & "<Br><Br>"
Txt. Write Jmail.log
Set txt = Nothing
Set FSO = Nothing
WScript.Echo "The message was sent successfully, a total of" &total& "mail was sent, sent to" &now "()
End Sub

Sub Closedb ()
If IsObject (conn) Then
Conn.close:Set Conn = Nothing
End If
End Sub

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.