Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2004, 03:28 PM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default help try to upload file to send in e-mail

hear is what my code look like for my send mail page..
Maybe some one can help me, to show me how to upload attachment to this page so my vistor can send picture or text file or anything. I need it so that they can attach file. I do have a simple msdn sql database and i also use webmatix to help me design my page so please explain it straight foward and in the simplest form thank you. Also this file is in asp.net



<%@ Page Language="VB" %>
<%@ import Namespace="System.Web.Mail" %>
<script runat="server">




    Sub buttonSend_Click(sender As Object, e As EventArgs)
    Dim emailMessage As MailMessage
    emailMessage = New MailMessage
    emailMessage.From = textFrom.Text
    emailMessage.Cc = textCopy.Text
    emailMessage.To = textTo.Text
    emailMessage.Subject = textSubject.Text
    emailMessage.Body = textMessage.Text
    SmtpMail.SmtpServer="localhost"
    Try
        SmtpMail.Send(emailMessage)
        labelStatus.Text = "Message sent!"
        buttonSend.Enabled = False
    Catch ex As Exception
        labelStatus.Text = "Unable to send e-mail message!"
     End Try
    End Sub

    Sub buttonNewMessage_Click(sender As Object, e As EventArgs)
    textFrom.Text = ""
    textCopy.Text = ""
    textTo.Text = ""
    textSubject.Text = ""
    textMessage.Text = ""
    buttonSend.Enabled = True
    labelStatus.Text = ""
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <h1>Pic Media E-mail&nbsp;System!
        </h1>
        <p>
            By: Anthony Szabo
        </p>
        <p>

        </p>
        <h1>&nbsp;Send an E-mail Message
        </h1>
        <p>

        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
            <strong>Send a e-mail to anyone. You just need your e-mail address to send the e-mail
            to anyone you like. You don't need to sign up for any service's, it easy as 123! All
            you do is enter your e-mail, if you want a carbon copy you fill in the CC:.&nbsp;If
            not you enter the person e-mail you are sending it to and the subject and message
            and hit send your done.</strong>
        </p>
        <p>
            <strong>From:&nbsp;
            <asp:TextBox id="textFrom" runat="server"></asp:TextBox>
            </strong><strong>
            <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="textFrom" ErrorMessage="You must enter you e-mail address!"></asp:RequiredFieldValidator>
            &nbsp;
            <asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ControlToValidate="textFrom" ErrorMessage="Invaild e-mail address!" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </strong>
        </p>
        <p>
            Cc:&nbsp;
            <asp:TextBox id="textCopy" runat="server"></asp:TextBox>
        </p>
        
        <p>
            <strong>To:&nbsp;
            <asp:TextBox id="textTo" runat="server" Width="157px"></asp:TextBox>
            </strong><strong>
            <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ControlToValidate="textTo" ErrorMessage="You must enter a recipient!"></asp:RequiredFieldValidator>
            &nbsp;
            <asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" ControlToValidate="textTo" ErrorMessage="Invaild e-mail address!" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </strong>
        </p>
        <p>
            <strong>Subject:&nbsp;
            <asp:TextBox id="textSubject" runat="server" Width="299px"></asp:TextBox>
            </strong>
        </p>
        <p>
            <strong>Message:<br />
            </strong><strong>
            <asp:TextBox id="textMessage" runat="server" Width="476px" Height="116px" TextMode="MultiLine"></asp:TextBox>
            </strong>
        </p>
        <p>
            <strong>
            <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ControlToValidate="textMessage" ErrorMessage="You must enter a message!"></asp:RequiredFieldValidator>
            </strong>
        </p>
        <p>
            <asp:Button id="buttonSend" onclick="buttonSend_Click" runat="server" Text="Send"></asp:Button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button id="buttonNewMessage" onclick="buttonNewMessage_Click" runat="server" Text="New Message"></asp:Button>
        </p>
        <p>
            <asp:Label id="labelStatus" runat="server" font-bold="True" forecolor="Red"></asp:Label>
            <br />
        </p>
        <h1>
            <br />
            &nbsp;
        </h1>
        </form>
</body>
</html>
 
Old August 6th, 2004, 11:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this.

Use a file type control that allows you to browse files and pick one from there.
Code:
<input id="myFile" type="file" name="myFile" runat="server" />
And on submit... use this
Code:
attachname = MyFile.PostedFile.FileName
If (attachname <> "") then
    attachname = attachname.substring(attachname.lastindexof("\")+1)
    MyFile.PostedFile.saveAs(Server.MapPath(attachname))
    emailMessage.Attachments.Add(new MailAttachment(Server.MapPath(attachname)))
End if
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail and attachments with PHP mail function Lofa Beginning PHP 1 June 2nd, 2008 03:24 PM
Send E-mail meme2002bh Access ASP 2 September 30th, 2005 12:53 AM
Not able to send a mail hums .NET Framework 2.0 5 November 16th, 2004 03:56 AM
upload, attach and send file naeemsyed Classic ASP Basics 4 March 7th, 2004 09:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.