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>
Related Article: asp.net 4.0 compatibility
is a ASP.NET discussion thread by dhanlak that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: ajax, asp.net, compatibility.
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