Jag använder följande kod för att skicka ut ett nyhetsbrev med aspsmartmail, så långt fungerar allt. Nu vill jag lägga till en funktion så att det går att bifoga en fil. Har kikat i dokumentationen utan framgång. Hur ska jag gå till väga? Vilken fil väljs på samma sida som skriver brevet på. Filen ligger inte på servern utan på datorn som det skicaks från. Måste man använda sig av en upload komponent då?
<%
On error resume next
Server.ScriptTimeOut = 180
Dim strSQL
Dim mySmartMail
Set mySmartMail = Server.CreateObject("aspSmartMail.SmartMail")
' Mail Server
' ***********
mySmartMail.Server = "****"
' From
' ****
mySmartMail.SenderName = Request.form("SenderName")
mySmartMail.SenderAddress = "noreplay@"
' Message
' *******
mySmartMail.Subject = Request.form("Subject")
mySmartMail.Body = Request.form("Body")
'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
'Set Conn = Server.CreateObject("ADODB.Connection")
'Conn.Open sConn
if Err.Number <> 0 then
Response.Write "Can't connect to the DataBase, Please check value of Data Source in the HTML form."
end if
' Create the RecordSet
' ********************
strSQL = "SELECT EMAIL, NAMN "
strSQL = strSQL & "FROM MEDLEMMAR"
Set Rs = Server.CreateObject("ADODB.recordset")
Set Rs.ActiveConnection = Conn
Rs.Source = strSQL
Rs.Open
Do while not Rs.EOF
' To
' **
if Rs("NAMN")<>"" Then
mySmartMail.Recipients.Add Rs("EMAIL"), Rs("NAMN")
else
mySmartMail.Recipients.Add Rs("EMAIL")
end if
' Send the message
' ****************
mySmartMail.SendMail
if err.number <> 0 then
response.write("<br>Error n°: " & err.number - vbobjecterror & "=" & err.description & "<br>")
else
Response.Write "<br>aspSmartMail has sent your message to " & mySmartMail.Recipients.Item(1).Address
end if
mySmartMail.Recipients.Clear
Rs.MoveNext
Loop
' Destruction
' ***********
response.redirect "../default.asp?kat=nyhetsbrev&sida=skriv.asp&status=ok"
Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
set mySmartMail = nothing
%>
Jepp. Ta emot filen med uploadkomponenten, spara den på serverns disk, använd mailkomponentens funktion för att attacha filer. Det borde inte vara några större problem.
r: om inte aspSmartMail har någon uppladdningsfunktion, men det har jag svårt att tänka mig, eftersom det finns en egen aspSmart-uppladdningskomponent.
Har nu börjat pilla lite med uploadkomponenten, tyvärr fungerar det inte som jag vill. Mailen går iväg, fast helt tomt. Går inte att skriva ut det som kommer med formuläret på föregående sida. Nån som har någon idé?
<!--#include file="../koppla.asp" -->
<!--#include file="../user.asp" -->
<%
Dim mySmartUpload
Dim sendername,subject,body, fil, file
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
sendername=mySmartUpload.Form("sendername")
subject=mySmartUpload.Form("subject")
body=mySmartUpload.Form("body")
For each file In mySmartUpload.Files
fil=file.FileName
Next
mySmartUpload.Upload
MySmartUpload.Save("\bilaga")
On error resume next
Server.ScriptTimeOut = 180
Dim strSQL
Dim mySmartMail
Set mySmartMail = Server.CreateObject("aspSmartMail.SmartMail")
' Mail Server
' ***********
mySmartMail.Server = "mail.aleborg.com"
' From
' ****
mySmartMail.SenderName = SenderName
mySmartMail.SenderAddress = "info90"
' Message
' *******
mySmartMail.Subject = Subject
mySmartMail.Body = Body
mySmartMail.Attachments.Add Server.MapPath("\bilaga\fil"),, false 'Vad ska man skriva här?
'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E"
'Set Conn = Server.CreateObject("ADODB.Connection")
'Conn.Open sConn
if Err.Number <> 0 then
Response.Write "Can't connect to the DataBase, Please check value of Data Source in the HTML form."
end if
' Create the RecordSet
' ********************
strSQL = "SELECT EMAIL, NAMN "
strSQL = strSQL & "FROM MEDLEMMAR"
Set Rs = Server.CreateObject("ADODB.recordset")
Set Rs.ActiveConnection = Conn
Rs.Source = strSQL
Rs.Open
Do while not Rs.EOF
' To
' **
if Rs("NAMN")<>"" Then
mySmartMail.Recipients.Add Rs("EMAIL"), Rs("NAMN")
else
mySmartMail.Recipients.Add Rs("EMAIL")
end if
' Send the message
' ****************
mySmartMail.SendMail
if err.number <> 0 then
response.write("<br>Error n°: " & err.number - vbobjecterror & "=" & err.description & "<br>")
else
Response.Write "<br>aspSmartMail has sent your message to " & mySmartMail.Recipients.Item(1).Address
end if
mySmartMail.Recipients.Clear
Rs.MoveNext
Loop
' Destruction
' ***********
response.redirect "../default.asp?kat=nyhetsbrev&sida=skriv.asp&status=ok"
Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
set mySmartMail = nothing
%>