Hello people, i need your help here;I want to use this code on asp.net application that has seperate files "Contactus.aspx and Contactus.aspx.cs" please how do i arrange these codes.

<%@ Import Namespace="System.Net" %>  
<%@ Import Namespace="System.Net.Mail" %>  
  
<script language="C#" runat="server">  
    protected void Page_Load(object sender, EventArgs e)  
    {  
       //create the mail message  
        MailMessage mail = new MailMessage();  
  
        //set the addresses  
        mail.From = new MailAddress("postmaster@HostingAccountDomain.com");  
        mail.To.Add("postmaster@HostingAccountDomain.com");  
         
        //set the content  
        mail.Subject = "This is an email";  
        mail.Body = "This is from system.net.mail using C sharp with smtp authentication.";  
        //send the message  
         SmtpClient smtp = new SmtpClient("mail.HostingAccountDomain.com");  
           
         NetworkCredential Credentials = new NetworkCredential("postmaster@HostingAccountDomain.com", "password");  
         smtp.Credentials = Credentials; 
         smtp.Send(mail);  
         lblMessage.Text = "Mail Sent";  
    }  
</script>  
<html>  
<body>  
    <form runat="server">  
        <asp:Label id="lblMessage" runat="server"></asp:Label>  
    </form>  
</body>  
</html>

Recommended Answers

All 2 Replies

Create all that code as a class, then you will be able to share that code in between multiple pages.

i've compliled a list of functions(and their overloads) to send emails (with or without multiple file attachements) into a single dll which is available for download here here . you may find it useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.