CDO message attach files

Discussion in 'ASP General' started by sallysmedly@yahoo.com, Jun 18, 2007.

  1. Guest

    Hi,

    I have a page where a user can browse for and attach 2 files to an
    email.

    The email works fine when I try to send a selected file from the
    server, but I have added in some script so that it sends the files the
    user has selected, but this part won't work.

    Any suggestions would be much appreciated.

    emailtest.asp

    <%
    Dim objMail
    Set objMail = Server.CreateObject("CDO.Message")
    Set objConfig = Server.CreateObject("CDO.Configuration")

    'Configuration:
    objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort

    objConfig.Fields(cdoSMTPServer)="auth.smtp.mydomain.co.uk"
    objConfig.Fields(cdoSMTPServerPort)=25
    objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
    objConfig.Fields(cdoSendUserName) = "username"
    objConfig.Fields(cdoSendPassword) = "password"

    'Update configuration
    objConfig.Fields.Update
    Set objMail.Configuration = objConfig

    objMail.From =""
    objMail.To = ""
    objMail.Subject = "You have a new message"
    objMail.TextBody = "You have a entry from "


    'this bit doesn't work
    for each file in Upload.Files
    fn=File.ExtractFilename
    objMail.AddAttachment Server.MapPath(fn),fn
    next
    'end of bit not working

    'this does work, but only attaches a fixed file, rather than user
    selected file
    'objMail.AddAttachment "http://www.mydomian.com/code.htm"
    objMail.Send

    If Err.Number = 0 Then
    Response.Write("Mail sent!")
    Else
    Response.Write("Error sending mail. Code: " & Err.Number)
    Err.Clear
    End If
    Set objMail=Nothing
    Set objConfig=Nothing
    %>


    form email:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    </head>

    <body>
    <form action="emailtest.asp" method="post" enctype="multipart/form-
    data" name="form1">
    <p>
    <input name="file1" type="file" id="file1">
    </p>
    <p>
    <input type="file" name="file2" id="file2">
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>
     
    , Jun 18, 2007
    #1
    1. Advertisements

  2. David Morgan Guest

    http://www.4guysfromrolla.com/webtech/112298-1.shtml

    Is the uploaded file in the same folder as the ASP page? It is unlikely
    that Server.MapPath should be used with ExtractFilename.

    Just attached based on the full folder name and file name of the uploaded
    file.



    <> wrote in message
    news:...
    > Hi,
    >
    > I have a page where a user can browse for and attach 2 files to an
    > email.
    >
    > The email works fine when I try to send a selected file from the
    > server, but I have added in some script so that it sends the files the
    > user has selected, but this part won't work.
    >
    > Any suggestions would be much appreciated.
    >
    > emailtest.asp
    >
    > <%
    > Dim objMail
    > Set objMail = Server.CreateObject("CDO.Message")
    > Set objConfig = Server.CreateObject("CDO.Configuration")
    >
    > 'Configuration:
    > objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort
    >
    > objConfig.Fields(cdoSMTPServer)="auth.smtp.mydomain.co.uk"
    > objConfig.Fields(cdoSMTPServerPort)=25
    > objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
    > objConfig.Fields(cdoSendUserName) = "username"
    > objConfig.Fields(cdoSendPassword) = "password"
    >
    > 'Update configuration
    > objConfig.Fields.Update
    > Set objMail.Configuration = objConfig
    >
    > objMail.From =""
    > objMail.To = ""
    > objMail.Subject = "You have a new message"
    > objMail.TextBody = "You have a entry from "
    >
    >
    > 'this bit doesn't work
    > for each file in Upload.Files
    > fn=File.ExtractFilename
    > objMail.AddAttachment Server.MapPath(fn),fn
    > next
    > 'end of bit not working
    >
    > 'this does work, but only attaches a fixed file, rather than user
    > selected file
    > 'objMail.AddAttachment "http://www.mydomian.com/code.htm"
    > objMail.Send
    >
    > If Err.Number = 0 Then
    > Response.Write("Mail sent!")
    > Else
    > Response.Write("Error sending mail. Code: " & Err.Number)
    > Err.Clear
    > End If
    > Set objMail=Nothing
    > Set objConfig=Nothing
    > %>
    >
    >
    > form email:
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    > <html>
    > <head>
    > <title>Untitled Document</title>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1">
    > </head>
    >
    > <body>
    > <form action="emailtest.asp" method="post" enctype="multipart/form-
    > data" name="form1">
    > <p>
    > <input name="file1" type="file" id="file1">
    > </p>
    > <p>
    > <input type="file" name="file2" id="file2">
    > </p>
    > <p>
    > <input type="submit" name="Submit" value="Submit">
    > </p>
    > </form>
    > </body>
    > </html>
    >
     
    David Morgan, Jun 29, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    1,208
    dave wanta
    Jul 11, 2003
  2. Matteo Migliore

    Attach ASP.NET ISAPI to custom files

    Matteo Migliore, Feb 25, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    414
    Matteo Migliore
    Feb 25, 2007
  3. Replies:
    0
    Views:
    882
  4. Warren Tang
    Replies:
    1
    Views:
    747
    Warren Tang
    Sep 17, 2008
  5. tabonni
    Replies:
    15
    Views:
    534
    Ray Costanzo [MVP]
    Sep 1, 2004
  6. Replies:
    0
    Views:
    514
  7. John O'gara
    Replies:
    3
    Views:
    143
    John O'gara
    Jan 22, 2010
  8. Replies:
    3
    Views:
    248
    Joel Goldstick
    Aug 8, 2013
Loading...