How to send email in ASP.NET C# -
i'm new asp.net c# area. i'm planning send mail through asp.net c# , smtp address isp:
smtp-proxy.tm.net.my
below tried do, failed.
<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="sendmail" %> <html> <head id="head1" runat="server"><title>email test page</title></head> <body> <form id="form1" runat="server"> message to: <asp:textbox id="txtto" runat="server" /><br> message from: <asp:textbox id="txtfrom" runat="server" /><br> subject: <asp:textbox id="txtsubject" runat="server" /><br> message body:<br> <asp:textbox id="txtbody" runat="server" height="171px" textmode="multiline" width="270px" /><br> <asp:button id="btn_sendmail" runat="server" onclick="btn_sendmail_click" text="send email" /><br> <asp:label id="label1" runat="server" text="label"></asp:label> </form> </body> </html>
and below code-behind:
using system; using system.web.ui.webcontrols; using system.net.mail; public partial class sendmail : system.web.ui.page { protected void btn_sendmail_click(object sender, eventargs e) { mailmessage mailobj = new mailmessage( txtfrom.text, txtto.text, txtsubject.text, txtbody.text); smtpclient smtpserver = new smtpclient("127.0.0.1"); try { smtpserver.send(mailobj); } catch (exception ex) { label1.text = ex.tostring(); } } }
ps: i'm sorry couldn't understand receiver/sender smtp concept, , trying understand whole concept here.
just go through below code.
smtpclient smtpclient = new smtpclient("mail.mywebsitedomainname.com", 25); smtpclient.credentials = new system.net.networkcredential("info@mywebsitedomainname.com", "myidpassword"); smtpclient.usedefaultcredentials = true; smtpclient.deliverymethod = smtpdeliverymethod.network; smtpclient.enablessl = true; mailmessage mail = new mailmessage(); //setting , , cc mail.from = new mailaddress("info@mywebsitedomainname", "myweb site"); mail.to.add(new mailaddress("info@mywebsitedomainname")); mail.cc.add(new mailaddress("myemailid@gmail.com")); smtpclient.send(mail);
Comments
Post a Comment