We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,188 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem with ASP.NET 4.0 built in classf or sending email.

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>
3
Contributors
2
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
denmarkstan
Junior Poster in Training
60 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 144
Skill Endorsements: 0

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

ckchaudhary
Junior Poster in Training
79 posts since Oct 2011
Reputation Points: 15
Solved Threads: 17
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0711 seconds using 2.68MB