09/10/2018, 23:03

ASP - Gửi mail theo định kỳ - HELP gấp !

Mình đang làm 1 dự án, trong đó có phần gửi mail cho thành viên thông báo danh sách chi tiết mỗi ngày uần háng (theo tuỳ chọn của thành viên). Mình dùng CDONTS để gửi mail. Tuy nhiên, mình ko biết phải làm sao để nó có thể tự động gửi vào đầu mỗi ngày uần háng. Nếu viết script trong biến cố Session_onStart của global.asa thì nó chỉ bắt đầu gửi khi có người đầu tiên truy cập vào web thôi. T__T

Mình muốn script chạy tự động khi qua một ngày mới (tức 0h00) mà ko cần có người mở trang web lên. Ko biết có cách nào ko ? Ai giúp mình với ! Cảm ơn trước.
Thất Kiếm viết 01:18 ngày 10/10/2018
Dùng SQL thử đi bạn, hồi trước mình nghiên cứu thì thấy nó có chức năng send mail đó.
Còn nếu dùng script thì có cái này cũng cool lắm:
Option Explicit
On Error Resume Next

' Declare our vars
Dim objWinHttp, strURL

' Request URL from 1st Command Line Argument. This is
' a nice option so you can use the same file to
' schedule any number of differnet scripts just by
' changing the command line parameter.
strURL = WScript.Arguments(0)

' Could also hard code if you want:
'strURL = "http://localhost/ScheduleMe.asp"

' For more WinHTTP v5.0 info, including where to get
' the component, see our HTTP sample:
' http://www.asp101.com/samples/winhttp5.asp
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5")
objWinHttp.Open "GET", strURL
objWinHttp.Send

' Get the Status and compare it to the expected 200
' which is the code for a successful HTTP request:
' http://www.asp101.com/resources/httpcodes.asp
If objWinHttp.Status <> 200 Then
' If it's not 200 we throw an error... we'll
' check for it and others later.
Err.Raise 1, "HttpRequester", "Invalid HTTP Response Code"
End If

' Since in this example I could really care less about
' what's returned, I never even check it, but in
' general checking for some expected text or some sort
' of status result from the ASP script would be a good
' idea. Use objWinHttp.ResponseText

Set objWinHttp = Nothing

If Err.Number <> 0 Then
' Something has gone wrong... do whatever is
' appropriate for your given situation... I'm
' emailing someone:
Dim objMessage
Set objMessage = Server.CreateObject("CDO.Message")
objMessage.To = "Your Name <user@some domain.com>"
objMessage.From = "Your Name <user@some domain.com>"
objMessage.Subject = "An Error Has Occurred in a " _
& "Scheduled Task"
objMessage.TextBody = "Error #: " & Err.Number & vbCrLf _
& "From: " & Err.Source & vbCrLf _
& "Desc: " & Err.Description & vbCrLf _
& "Time: " & Now()

objMessage.Send
Set objMessage = Nothing
End If
Vào đây tham khảo thêm nè: http://www.asp101.com/articles/john/...le/default.asp
Nhớ scroll xuống dưới cùng, xem method 3 đó, đoạn code trên là method 3, ok nhất

Nếu làm bằng .Net thì còn simple hơn nữa.
Squall Leonahear viết 01:13 ngày 10/10/2018
Cám ơn bạn nhiều nha. Nhưng mình ko rõ file vbs có kết nối database để lấy điạ chỉ mail của từng người được ko nhỉ ? Để mình thử xem vậy. À, dùng .Net thì phải làm sao hả bạn (mình ko rành .Net lắm T__T) ?
lytamhoana6cntt viết 01:11 ngày 10/10/2018
Dùng CDO trong asp 3.0 có send được Tiếng Việt Unicode không?
Squall Leonahear viết 01:16 ngày 10/10/2018
Ok ! Mình giải quyết xong rồi. Dùng Scheduled Task và CDO để gửi mail đi. Cám ơn mọi người nhiều lắm !
Bài liên quan
0