 |
|
ASP CDO.Message ส่งเมล์แบบมีไฟล์แนบ แต่ผู้รับได้รับไฟล์แนบหลายไฟล์ ทำไงดีคะ รบกวนช่วยด้วยค่ะ |
|
 |
|
|
 |
 |
|

Code (ASP)
<% On Error Resume Next %>
<html>
<head>
<title>ThaiCreate.Com ASP CDO.Message Send Mail</title>
</head>
<body>
<%
'response.write nfacility
Dim objFSO,objFiles,Vol,objFilename
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
set objFiles = objFSO.GetFolder(Server.MapPath("excelfiletmp"))
Dim myMail,HTML,strMsg,strFileName
Set myMail = Server.CreateObject("CDO.Message")
'*** If Using Remote Server ***'
Dim cdoConfig
Set cdoConfig = myMail.Configuration
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
For Each Vol in objFiles.Files
strMsg = ""
strMsg = strMsg &"<h1>My Message</h1><br>"
objFilename=Vol.Name
splitobjFilename=Split(objFilename,"_")
nobjFilename=ubound(splitobjFilename,1)+1
splitname1=splitobjFilename(0)
strFileName = Server.MapPath("excelfiletmp/"&objFilename)
myMail.AddAttachment strFileName
myMail.From = "[email protected]"
myMail.To = splitobjFilename(0)&"@hotmail.com"
myMail.Subject = "test"
myMail.HTMLBody = strMsg
myMail.Send
Next
Response.write ("Mail Sending.")
Set myMail = Nothing
Set objFiles = Nothing
Set objFSO = Nothing
%>
</body>
</html>
ตาม code ด้านบน
คือต้องการแนบไฟล์ใน folder ไปยัง email ผู้รับตามชื่อไฟล์
เช่น ไฟล์ a_21052014.xslx ส่งไป mail : [email protected]
b_21052014.xslx ส่งไป mail : [email protected]
c_21052014.xslx ส่งไป mail : [email protected]
แต่ผลลัพธ์ที่ได้กลับเป็น
ส่งไป mail : [email protected] ได้รับไฟล์ a_21052014.xslx
ส่งไป mail : [email protected] ได้รับไฟล์ a_21052014.xslx ,b_21052014.xslx
ส่งไป mail : [email protected] ได้รับไฟล์ a_21052014.xslx ,b_21052014.xslx , c_21052014.xslx
ต้องแก้ยังไง รบกวนด้วยค่ะ
Tag : ASP
|
|
 |
 |
 |
 |
Date :
2014-05-22 10:50:00 |
By :
oyoyho |
View :
1344 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่งหลายคนใช้ Comma (,) หรือจะเป็นพวก CC / Bcc
ส่วนหลาย ๆ ไฟล์เพิ่มบรรทัดได้เลยครับ
Code (ASP)
myMail.AddAttachment Server.MapPath("excelfiletmp/"&objFilename1)
myMail.AddAttachment Server.MapPath("excelfiletmp/"&objFilename2)
myMail.AddAttachment Server.MapPath("excelfiletmp/"&objFilename3)
|
 |
 |
 |
 |
Date :
2014-05-22 12:59:37 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณวินคะ คือต้องการส่งแค่ 1 mail ต่อ 1 file เท่านั้นค่ะ
แต่ตั้งแต่ mail ที่ 2 เป็นต้นไป ทำไมได้รับหลาย file ก็ไม่รู้ค่ะ ดิฉันลองเปลี่ยน code โดยกำหนดค่า i แล้วก็ยังไม่ได้ รบกวนอีกทีค่ะ
Code (ASP)
Dim objFSO,objFiles,Vol,oFiles
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
set objFiles = objFSO.GetFolder(Server.MapPath("excelfiletmp"))
Set oFiles = objFiles.Files
ReDim objFilename(oFiles.Count)
ReDim objpath(oFiles.Count)
Dim myMail,HTML,strMsg,strFileName
Set myMail = Server.CreateObject("CDO.Message")
'*** If Using Remote Server ***'
Dim cdoConfig
Set cdoConfig = myMail.Configuration
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
i=0
For Each Vol in objFiles.Files
strMsg = ""
strMsg = strMsg &"<h1>My Message</h1><br>"
objFilename(i)=Vol.Name
splitobjFilename=Split(objFilename(i),"_")
nobjFilename=ubound(splitobjFilename,1)+1
splitname1=splitobjFilename(0)
objpath(i) = Server.MapPath("excelfiletmp/"&objFilename(i))
response.write objpath(i)&"<br>"
myMail.AddAttachment objpath(i)
myMail.From = "[email protected]"
myMail.To = splitobjFilename(0)&"@hotpot.co.th"
myMail.Subject = "test"
myMail.HTMLBody = strMsg
myMail.Send
i=i+1
Next
Set myMail = Nothing
Set objFiles = Nothing
Set objFSO = Nothing
|
 |
 |
 |
 |
Date :
2014-05-22 15:44:32 |
By :
oyoyho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|