smtp mail problemhttp://forums.asp.net/t/1468450.aspx/1?smtp+mail+problemMon, 21 Sep 2009 10:49:34 -040014684503394878http://forums.asp.net/p/1468450/3394878.aspx/1?smtp+mail+problemsmtp mail problem <p>&nbsp;hi...can help me convert the following code to C#?</p> <pre class="prettyprint">Dim oMail = Server.CreateObject(&quot;CDO.Message&quot;) Dim iConf = Server.CreateObject(&quot;CDO.Configuration&quot;) Dim Flds = iConf.Fields iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusing&quot;).ToString()) iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString() iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpconnectiontimeout&quot;).ToString()) iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserverport&quot;).ToString()) iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpauthenticate&quot;).ToString()) iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString() iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString() iConf.Fields.Update() oMail.Configuration = iConf oMail.To = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString() oMail.From = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString() oMail.Subject = &quot;Enquiry Email from Web Visitor&quot; oMail.htmlBody = strEmailText oMail.Send() oMail = Nothing iConf = Nothing Flds = Nothing</pre> <p><br> &nbsp;</p> 2009-09-09T08:48:05-04:003394906http://forums.asp.net/p/1468450/3394906.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <pre class="prettyprint">{ var oMail = Server.CreateObject(&quot;CDO.Message&quot;); var iConf = Server.CreateObject(&quot;CDO.Configuration&quot;); var Flds = iConf.Fields; iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusing&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString(); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpconnectiontimeout&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserverport&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpauthenticate&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString(); iConf.Fields.Update(); oMail.Configuration = iConf; oMail.To = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString(); oMail.From = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); oMail.Subject = &quot;Enquiry Email from Web Visitor&quot;; oMail.htmlBody = strEmailText; oMail.Send(); oMail = null; iConf = null; Flds = null; }</pre> <p><br> Hope&nbsp;this helps&nbsp;</p> 2009-09-09T09:00:03-04:003394911http://forums.asp.net/p/1468450/3394911.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>Here it is (next time you can use online translator: <a href="http://www.developerfusion.com/tools/convert/vb-to-csharp/"> http://www.developerfusion.com/tools/convert/vb-to-csharp/</a>):<br> </p> <pre class="prettyprint">var oMail = Server.CreateObject(&quot;CDO.Message&quot;); var iConf = Server.CreateObject(&quot;CDO.Configuration&quot;); var Flds = iConf.Fields; iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusing&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString(); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpconnectiontimeout&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserverport&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;) = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpauthenticate&quot;).ToString()); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); iConf.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;) = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString(); iConf.Fields.Update(); oMail.Configuration = iConf; oMail.To = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString(); oMail.From = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); oMail.Subject = &quot;Enquiry Email from Web Visitor&quot;; oMail.htmlBody = strEmailText; oMail.Send(); oMail = null; iConf = null; Flds = null;</pre> <p><br> </p> &nbsp; <p></p> 2009-09-09T09:01:35-04:003396727http://forums.asp.net/p/1468450/3396727.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;sorry.....may i know what is var? how come my c# not supporting that?</p> 2009-09-10T04:34:31-04:003399210http://forums.asp.net/p/1468450/3399210.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;guys...what is var??? how come i couldn't use var.....i did add using System.linq</p> 2009-09-11T07:04:13-04:003399243http://forums.asp.net/p/1468450/3399243.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p><em>hi </em></p> <p>try this </p> <p><font color="#0000ff" size="2"></p> <p>using</p> </font><font size="2">System.Net.Mail; at the top of the page</font> <p></p> <pre class="prettyprint">SmtpClient stc = new SmtpClient(); stc.Host = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString(); stc.Timeout = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpconnectiontimeout&quot;).ToString()); stc.Port = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserverport&quot;).ToString()); stc.Credentials = new System.Net.NetworkCredential( System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(), System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString()); stc.DeliveryMethod = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusing&quot;).ToString()); MailMessage mm = new MailMessage(); mm.From = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); ; mm.To = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString(); mm.Subject = &quot;Enquiry Email from Web Visitor&quot;; mm.IsBodyHtml = true; mm.Body = strEmailText; stc.Send(mm);</pre> <p><br> &nbsp;</p> 2009-09-11T07:20:45-04:003399246http://forums.asp.net/p/1468450/3399246.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;hi guys....is there anyway to replace <strong><u>var </u></strong>visual 2003 seems no supporting that</p> 2009-09-11T07:22:37-04:003399256http://forums.asp.net/p/1468450/3399256.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p><img title="Cry" alt="Cry" src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-cry.gif" border="0">&nbsp;i don't have(&nbsp;using System.Net.Mail)!!!!&nbsp;</p> 2009-09-11T07:28:25-04:003399263http://forums.asp.net/p/1468450/3399263.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>hi </p> <p>&nbsp;refer the following link </p> <p><a href="http://www.google.co.in/search?hl=en&amp;q=send&#43;mail&#43;using&#43;CDO.Message&#43;in&#43;c%23&amp;meta=&amp;aq=8&amp;oq">http://www.google.co.in/search?hl=en&amp;q=send&#43;mail&#43;using&#43;CDO.Message&#43;in&#43;c%23&amp;meta=&amp;aq=8&amp;oq</a>=</p> 2009-09-11T07:32:40-04:003399284http://forums.asp.net/p/1468450/3399284.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>both of the code i place into same visual studio, how come vb supporting it while c# not supporting it?</p> 2009-09-11T07:43:11-04:003399315http://forums.asp.net/p/1468450/3399315.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>You tried to use clasic asp code in ASP.NET page and that's why it's not working. You should try with this:<br> </p> <pre class="prettyprint">System.Net.Mail.SmtpClient email = new System.Net.Mail.SmtpClient(); System.Net.NetworkCredential credential = new System.Net.NetworkCredential(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(), System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString()); email.Host = System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString(); email.Credentials = credential; System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage(); mailMsg.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString()); mailMsg.To.Add(new System.Net.Mail.MailAddress(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString())); mailMsg.Subject = &quot;Enquiry Email from Web Visitor&quot;; mailMsg.Body = strEmailText; mailMsg.IsBodyHtml = true; email.Send(mailMsg);</pre> <p><br> </p> &nbsp; <p><br> </p> 2009-09-11T08:00:34-04:003399334http://forums.asp.net/p/1468450/3399334.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;hi <a href="/members/harieis.aspx">harieis</a>,</p> <p>you get ur solution to following url :</p> <p><a href="/t/1457421.aspx">http://forums.asp.net/t/1457421.aspx</a></p> <p>&nbsp;</p> <p>&nbsp;</p> <p>and var is variable type that just use for storing data&nbsp; to result type</p> <p>&nbsp;</p> <p>var is type that use like following :</p> <p>&nbsp;</p> <p>var data = CustomerDetailBl.GetData(id);</p> <p>&nbsp;</p> <p>var data&nbsp; = new string[];</p> <p>&nbsp;</p> <p>that just type that contaion any type of object or anything....</p> <p>&nbsp;</p> <p>bye</p> <p>&nbsp;</p> <p>Mark as Answer if get ur solution</p> <p>&nbsp;</p> <p>Thanks</p> 2009-09-11T08:08:47-04:003400846http://forums.asp.net/p/1468450/3400846.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;dear kipo....my visual studio doesn't support System.Net.Mail.SmtpClient...is there anyway else to do it?</p> 2009-09-12T01:31:46-04:003402577http://forums.asp.net/p/1468450/3402577.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <pre class="prettyprint">System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage(); message.Fields.Add(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;, Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusing&quot;).ToString())); message.Fields.Add(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;, System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString()); message.Fields.Add(&quot;http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout&quot;, Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpconnectiontimeout&quot;).ToString())); message.Fields.Add(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;, Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserverport&quot;).ToString())); message.Fields.Add( &quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;,Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpauthenticate&quot;).ToString())); message.Fields.Add( &quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;,System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString()); message.Fields.Add( &quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;,System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendpassword&quot;).ToString()); message.From=System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;sendusername&quot;).ToString(); message.To=System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;emailto&quot;).ToString(); message.Subject=&quot;Enquiry Email from Web Visitor&quot;; message.Body= strEmailText; //System.Web.Mail.SmtpMail.SmtpServer=System.Configuration.ConfigurationSettings.AppSettings.Get(&quot;smtpserver&quot;).ToString(); try { try { System.Web.Mail.SmtpMail.Send(message); } catch (Exception ex) { lblMessage.Text = &quot;Error &quot; &#43; ex.InnerException.ToString(); } } catch(Exception ex) { lblMessage.Text = lblMessage.Text &#43; &quot;Error &quot; &#43; ex.ToString(); }</pre> <p><br> &nbsp;</p> <p>Error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)</p> <p>How to solve this error code?</p> 2009-09-14T02:44:03-04:003402674http://forums.asp.net/p/1468450/3402674.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>firstly i say that always use gmail becsause in asp.net gmail is better becuase other mail service provider not give a good service&nbsp;</p> <p>so &nbsp;i use alwayse gogle mail service if you thing to send emil then take it my code</p> <p><br> </p> <p><br> </p> &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;using System;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;using System.Collections.Generic;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;using System.Web;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;using System.Web.UI;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;using System.Web.UI.WebControls;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;public partial class _Default : System.Web.UI.Page&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;protected void Page_Load(object sender, EventArgs e)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;protected void btn_Click(object sender, EventArgs e)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// declare variable for sending mail&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;string tomail = this.txtto.Text;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;string subject = this.txtsub.Text;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;string body = this.txtbody.Text;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// send a mail by gmail account&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;System.Net.Mail.MailMessage MyMailMessage =&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new System.Net.Mail.MailMessage(&quot;anirudhakumar.gupta@gmail.com&quot;, tomail,&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;subject, body);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;MyMailMessage.IsBodyHtml = false;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//Proper Authentication Details need to be passed when sending email from gmail&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;System.Net.NetworkCredential mailAuthentication = new&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;System.Net.NetworkCredential(&quot;anirudhakumar.gupta@gmail.com&quot;, &quot;zzxxccvv&quot;);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//Smtp Mail server of Gmail is &quot;smpt.gmail.com&quot; and it uses port no. 587&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//For different server like yahoo this details changes and you can&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//get it from respective server.&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(&quot;smtp.gmail.com&quot;, 587);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//Enable SSL&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mailClient.EnableSsl = true;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mailClient.UseDefaultCredentials = false;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mailClient.Credentials = mailAuthentication;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;try&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mailClient.Send(MyMailMessage);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;catch (System.Net.Mail.SmtpException ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.Write(ex.ToString());&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;}&lt;/div&gt; &lt;div&gt;&lt;/div&gt; <p></p> <p></p> <pre class="prettyprint">using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn_Click(object sender, EventArgs e) { // declare variable for sending mail string tomail = this.txtto.Text; string subject = this.txtsub.Text; string body = this.txtbody.Text; // send a mail by gmail account System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(&quot;anirudhakumar.gupta@gmail.com&quot;, tomail, subject, body); MyMailMessage.IsBodyHtml = false; //Proper Authentication Details need to be passed when sending email from gmail System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(&quot;anirudhakumar.gupta@gmail.com&quot;, &quot;zzxxccvv&quot;); //Smtp Mail server of Gmail is &quot;smpt.gmail.com&quot; and it uses port no. 587 //For different server like yahoo this details changes and you can //get it from respective server. System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(&quot;smtp.gmail.com&quot;, 587); //Enable SSL mailClient.EnableSsl = true; mailClient.UseDefaultCredentials = false; mailClient.Credentials = mailAuthentication; try { mailClient.Send(MyMailMessage); } catch (System.Net.Mail.SmtpException ex) { Response.Write(ex.ToString()); } } }</pre> <p><br> <br> </p> <p></p> 2009-09-14T04:26:50-04:003402766http://forums.asp.net/p/1468450/3402766.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;sorry...i don't have System.Net.Mail, i only able to get System.net</p> 2009-09-14T05:42:00-04:003402804http://forums.asp.net/p/1468450/3402804.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>For what version of .NET Framework is your app designed?</p> 2009-09-14T06:07:02-04:003402923http://forums.asp.net/p/1468450/3402923.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;version 1.1.4322</p> 2009-09-14T07:21:49-04:003403093http://forums.asp.net/p/1468450/3403093.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>That's why the code isn't working - it's for .NET 2.0 and above. To solve your problem, take a look at this&nbsp;article:&nbsp;<a href="http://uxuf.blogspot.com/2006/08/sending-mail-with-systemwebmail-net-11.html">http://uxuf.blogspot.com/2006/08/sending-mail-with-systemwebmail-net-11.html</a></p> 2009-09-14T08:48:31-04:003404896http://forums.asp.net/p/1468450/3404896.aspx/1?Re+smtp+mail+problemRe: smtp mail problem <p>&nbsp;kipo, the same error occur using the source code provided.....</p> <p>the last option i have is to embed vb codes in c#....is there a way to do it?</p> 2009-09-15T02:09:20-04:00