Avatar billede roadi Nybegynder
18. februar 2003 - 22:45 Der er 1 kommentar og
1 løsning

Vedhæfte filer til en Jmail HTML mailer ved hjælp af Persists

Hej Experter!

Jeg har en mail funktion på min hjemmeside som bruger Jmail med HTML. Jeg ville meget gerne kunne uploade en fil til serveren og vedhæfte den i min mail.

Jeg har lavet Upload funktionen og Maildelen, men jeg kan ikke få jmail til at vedhæfte filen, hvad går der galt?

Her er min kode:


<%
            if session("to_id") = "all" then
           
                Response.Write session("to_id") & "<br>"
                Response.Write session("subject") & "<br>"
                Response.Write session("msg")
           
           
           
               
                Set Upload = Server.CreateObject("Persits.Upload.1")

                        ' This is needed to enable the progress indicator
                        'Upload.ProgressID = Request.QueryString("PID")

                        'Count = Upload.Save


                        ' we use memory uploads, so we must limit file size
                            'Upload.SetMaxSize 100000, True

                        ' Save to memory. Path parameter is omitted
                            Upload.Save "d:\home\allcommittednet\www\tcfunc\archive\"

                                               
                        ' access subdirectory specified by user
                            'subdir = Upload.Form("subdir")

                        ' Build path string
                            'Path = "f:\roadi.dk\team-go\files\" & subdir
                            Path = "d:\home\allcommittednet\www\tcfunc\archive\"
                            session("path") = "d:\home\allcommittednet\www\tcfunc\archive\"

                        ' Create path, ignore "already exists" error
                            Upload.CreateDirectory Path, True

                        ' Save files to it. Our form has only one file item
                        ' but this code is generic.
   
                            'For Each File in Upload.Files
                            '    File.SaveAs Path & "\" & File.FileName
                               
                            For Each File In Upload.Files
                                File.move  path & File.ExtractFileName
                           
                    Set rs = Server.CreateObject("ADODB.RecordSet")
                    strSQL = "Select * From tc_mail_archive"
                    rs.Open strSQL, Conn, 1,3


                                        rs.addnew
                                            rs("subject")            = session("subject")
                                            rs("msg")                = session("msg")
                                            rs("senderid")            = session("id")
                                            rs("date")                = now
                                            'rs("attachment")        = 1       
                                            rs("attached_file")        = File.ExtractFileName
                                            rs("attached_details")    = upload.form("details")
                                            rs.Update
                                        rs.Close
                                        Set rs = Nothing
                                    Session("filename") = file.extractFileName
                       
                                Response.Write "File saved as " & "<b>" & File.Path & "</B>"
                            Next   
               
               
           
            SQLstmt = "SELECT * FROM titles where title ='TC'"
                        Conn.Execute (SQLstmt)
                        Set Titles = conn.Execute(SQLstmt)
               
                        SQLstmt = "SELECT * FROM titles where title ='RVP'"
                        Conn.Execute (SQLstmt)
                        Set Titles_RVP = conn.Execute(SQLstmt)
               
                        SQLstmt = "SELECT * FROM titles where title ='SVP'"
                        Conn.Execute (SQLstmt)
                        Set Titles_SVP = conn.Execute(SQLstmt)
               
                                   
                        SQLstmt = "SELECT * FROM users where title =" & titles("id") & "or title=" & titles_rvp("id") & "or title=" & titles_svp("id") & "order by Firstname asc;"
                        Conn.Execute (SQLstmt)
                        Set maillist = conn.Execute(SQLstmt)
                       
                        'do while not maillist.eof
                               
                                '// Nyhedstext, Overskrift og Mailfooter til Udsendelse. Roadi 111002
                           
                                strNEWSTEXT        = replace(session("msg"),vbcrlf,"<br>")
                                strHEADLINE        = session("subject")
                                strFooter        = replace(pagetext("mail_footer"),vbcrlf,"<br>")
                       
                        str = strNEWSTEXT
                       
                                Function LinkString2(strInput)
                                        Set objRegExpHTTP1 = New RegExp
                                        Set objRegExpHTTP2 = New RegExp
                                        Set objRegExpMAIL  = New RegExp

                                        objRegExpHTTP1.Pattern = "(http|ftp|nntp)(:\/\/[\w\._-]+\.[\w\._-]+\S*)"
                                        objRegExpHTTP2.Pattern = "(^|[^\/])(www[^\.\s]?\.[\w\._-]+\.[A-Za-z]{2,3}[\w\S]*)"
                                        objRegExpMAIL.Pattern = "(\S+@{1}\S+\.\w+\b)"

                                        objRegExpHTTP1.Global = True
                                        objRegExpHTTP2.Global = True
                                        objRegExpMAIL.Global  = false

                                        objRegExpHTTP1.IgnoreCase = True
                                        objRegExpHTTP2.IgnoreCase = True
                                        objRegExpMAIL.IgnoreCase  = True

                                        strOutput = objRegExpHTTP1.Replace(strInput, " <a href='$1$2' target='_blank' class='smallink'>$1$2</a> ")
                                        strOutput = objRegExpHTTP2.Replace(strOutput, " $1<a href='http://$2' target='_blank' class='smallink'>$2</a> ")
                                        strOutput = objRegExpMAIL.Replace(strOutput, "<a href=""mailto:$1"" class='smallink'>$1</a>")

                                        objRegExpHTTP2.Pattern = "(<br>|[,.)\]\}])('>)"
                                        strOutput = objRegExpHTTP2.Replace(strOutput, "$2")
                                        objRegExpHTTP2.Pattern = "(<br>|[,.)\]\}])(' target=)"
                                        strOutput = objRegExpHTTP2.Replace(strOutput, "$2")
                                        objRegExpHTTP2.Pattern = "(<br>|[,.)\]\}])(</a>)"
                                        strOutput = objRegExpHTTP2.Replace(strOutput, "$2$1")

                                        Set objRegExpHTTP2 = Nothing
                                        set objRegExpHTTP1 = Nothing
                                        Set objRegExpMAIL  = Nothing

                                        LinkString2 = strOutput
                                        End Function
                       
                       
                            while not maillist.eof
                                    count = 1
                                    lastcount = 25
 
                                while not maillist.eof and count < lastcount
                                    count = count+1
                                   
                                    on error resume next 
                       
                       
                       
                        'Variabler til maildelen // Roadi 090802
                           
                                strEmailAddress = maillist("email")
                                strFirstname    = maillist("firstname")
                                strLastname        = maillist("lastname")
                               
                       
                            'Jmail HTML mail // Roadi 071002
                       
                       
                        Set JMail = Server.CreateObject("JMail.SMTPMail")
                            'JMail.Silent = true
                            'JMail.Logging = true
                           
                            set attachment = session("path") & session("filename")
                            if attachment.IsFile then
                                jmail.AddCustomAttachment attachment.filename, attachment.item, false
                            end if

                            Response.Write attachment
                           
                            JMail.ServerAddress = mailserver
                            JMail.Sendername = Afsendernavn
                            JMail.Sender = Afsendermail
                            Jmail.ContentType = "text/html"
                            JMail.Priority = 1
                            JMail.AddHeader    "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

                            JMail.Subject = strHeadline
                   
                            JMail.Body = HTMLHeader
                            Jmail.body = jmail.body + HTMLHeadline & strheadline
                            Jmail.body = jmail.body + HTMLBODY & linkString2 (str)
                            Jmail.body = jmail.body + HTMLRGDS & "Med venlig Hilsen" & "<br></p>" & "<a href=mailto:" & strSendermail & " class=smallink>" & strSender & "</a>"
                            Jmail.body = jmail.body + HTMLBlackline & strFOOTER
                            Jmail.body = jmail.body + HTMLBlackline2
                            Jmail.body = jmail.body + HTMLEND
                           
                            JMail.ClearRecipients()
                            JMail.AddRecipient "lilja@graficom.dk"
                            Jmail.lazysend = true
                            JMail.Execute
                           
                           
                            set JMail = nothing
                           
                       
                       
                       
                            response.write "<tr><td>Meddelelse er sendt til: "& strEmailaddress &"</td></td>"
                           
                        maillist.movenext
                        wend
                        Response.Write "<tr><td>" & count & "</td></tr>"
                    wend
                        'loop
                        'maillist.close
                       
                            'Response.Write "<tr><td>Du bliver sendt tilbage til nyhederne omlidt</td></tr>"
                            Response.Write "<tr><td>Alle har nu modtaget deres mail.</td></tr>"
                            Response.End
                               

Jeg håber at i kan hjælpe...

Med venlig hilsen

Roadi
Avatar billede medions Nybegynder
18. februar 2003 - 22:52 #1
Attachments Attaching files to your w3 JMail emails requires that the file you wish to attach resides on the webserver. However, using w3 Upload, you can let the user upload the file to the webserver and attach it on the fly. Check out the samples below to find out more...



First of all we a form where the user can enter his email message and select which file to attach.


  JMailUpload.asp
<html>
<head>
<title>emailform</title>
</head>
<body>
<font face="verdana, arial" size="2"><b>
<form method="post" action="JmailUploadProcess.asp" ENCTYPE="multipart/form-data">
Complete this form and click the submit-button. We will answer your
questions as soon as possible.
<br><br>
Your name <br>
<input type="text" size="25" name="name"><br>

Your email <br>
<input type="text" size= "25" name= "email"><br>< /FONT>

Recipient email <br>
<input type= "text" size= "25" name= "recipient"><br>< /FONT>

State your business <br>
<select name="subject" size="1">
<option value="help">help
<option value="tips">tips
<option value="other">other
</select>
<br>

Enter your question <br>
<textarea name="body" cols="40" rows="15" wrap="PHYSICAL"></textarea>
<br>

Attachments <br>
<input type="file" name="attachment">
<br>
<br>
<input type="submit" value=" Submit ">
</form>
</b></font>
</body>
</html>

Okay, Now lets put all that info into our email. Again, notice how we use the Upload object instead of the Request object.


  JMailUploadProcess.asp

<%@LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
<%
' Create the JMail message Object
set msg = Server.CreateOBject( "JMail.Message" )
Set upload = Server.CreateObject( "w3.Upload" )

' Check for attachments and add them to the email
set attachment = upload.Form( "attachment" )
if attachment.IsFile then
  msg.AddCustomAttachment attachment.filename, attachment.item, false
end if

' Set logging to true to ease any potential debugging
' And set silent to true as we wish to handle our errors ourself
msg.Logging = true
msg.silent = true

' Get the form variables, using the upload object
Name = upload.Form("name")
SenderEmail = upload.Form("email")
Subject = "Regarding " & upload.Form ("subject")
Recipient = upload.Form("recipient")
Body = upload.Form("body")

' And apply them to the message
msg.From = SenderEmail
msg.FromName = Name

msg.AddRecipient Recipient
msg.Subject = Subject

msg.Body = Body

' To capture any errors which might occur, we wrap the call in an IF statement
if not msg.Send( "mail.myDomain.net" ) then
  Response.write "<pre>" & msg.log & "</pre>"
else
  Response.write "Message sent succesfully!"
end if


' And we're done! the message has been sent.
%>
</BODY>
</HTML>



   


   

There you go! Notice how w3 Upload never actually saves the file to your disc, but rather just attaches the file to the email. Quite nifty as your webserver wont get cluttered with files.

//>Rune
Avatar billede longshanks Nybegynder
18. februar 2003 - 22:53 #2
Noget i denne stil:
JMail.AddAttachment( "c:\\autoexec.bat" );
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester