SmtpClient smtpClient; private void Connection() { smtpClient = new SmtpClient(); smtpClient.Host = '' smtpClient.Port = '' } public MethodName () { Connection(); MailMessage message = new MailMessage(); MailAddress fromAddress = new MailAddress(' '); message.From = fromAddress; message.To.Add(ToAddress); message.Subject = " "; message.IsBodyHtml = false; message.Body = ' ' smtpClient.Send(message); }
Best Regards, Rohan Laghate
Thank you for posting at Dotnetfunda [Administrator]
Thanks, T.Saravanan
<%@ Import Namespace="System.Web" %> <%@ Import Namespace="ASPEMAILLib" %> <%@ Import Namespace="System.Reflection" %> <script runat="server" LANGUAGE="C#"> void Page_Load(Object Source, EventArgs E) { // Change this to your own SMTP server String strHost = "localhost"; if( IsPostBack ) { // MailSender object declaration ASPEMAILLib.IMailSender objMail; objMail = new ASPEMAILLib.MailSender(); objMail.Host = strHost; objMail.From = "info@persits.com"; // From address objMail.FromName = "AspEmail Live Demo"; // optional String strToAddress = txtTo.Value.Trim(); if( !Regex.IsMatch( strToAddress, @"(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})" ) ) { txtMsg.InnerHtml = "<font color=red>Invalid email address.</font>"; return; } // To address, 2nd argument omitted. objMail.AddAddress( txtTo.Value, Missing.Value ); // Message subject objMail.Subject = objMail.EncodeHeader( txtSubject.Value, "UTF-8" ); // Enable Unicode objMail.ContentTransferEncoding = "Quoted-Printable"; objMail.CharSet = "UTF-8"; // Message body objMail.Body = txtBody.Value; // Include a disclaimer objMail.Body += "\r\n\r\n-----------------------------------\r\n\r\nThis message was generated by the AspEmail live demo on-line application. Persits Software, Inc. is not responsible for its content."; try { objMail.Send(Missing.Value); txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>"; } catch(Exception e) { txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>"; } } } </script> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8"> <TITLE>AspEmail Live Demo: Unicode-enabled Message Sending</TITLE> </HEAD> <BODY style="font-family: arial narrow; font-size: 10pt"> <h2>AspEmail Live Demo: Unicode-enabled Message Sending</h2> <P> <FORM METHOD="POST" RUNAT="Server"> <TABLE CELLSPACING=2 CELLPADDING=2 BGCOLOR="#E0E0E0" style="border: 1pt black solid; border-collapse: collapse"> <TR> <TD>To:</TD> <TD><INPUT TYPE="TEXT" size="40" ID="txtTo" RUNAT="Server"></TD> </TR> <TR> <TD>Subject:</TD> <TD><INPUT TYPE="TEXT" size="40" ID="txtSubject" RUNAT="Server"></TD> </TR> <TR> <TD valign="top">Body:</TD> <TD><TEXTAREA ID="txtBody" RUNAT="Server" Rows="10" Cols="40"></TEXTAREA></TD> </TR> <TR> <TD COLSPAN=2><INPUT TYPE="SUBMIT" NAME="Send" VALUE="Send Message" RUNAT="Server"></TD> </TR> </TABLE> <P> <div id="txtMsg" runat="server"/><BR> </FORM> </BODY> </HTML>
LP MER
Login to post response