Error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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)
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("anirudhakumar.gupta@gmail.com", 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("anirudhakumar.gupta@gmail.com", "zzxxccvv");
//Smtp Mail server of Gmail is "smpt.gmail.com" 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("smtp.gmail.com", 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());
}
}
}
kipo
All-Star
16475 Points
2811 Posts
Re: smtp mail problem
Sep 11, 2009 08:00 AM|LINK
You tried to use clasic asp code in ASP.NET page and that's why it's not working. You should try with this:
System.Net.Mail.SmtpClient email = new System.Net.Mail.SmtpClient(); System.Net.NetworkCredential credential = new System.Net.NetworkCredential(System.Configuration.ConfigurationSettings.AppSettings.Get("sendusername").ToString(), System.Configuration.ConfigurationSettings.AppSettings.Get("sendpassword").ToString()); email.Host = System.Configuration.ConfigurationSettings.AppSettings.Get("smtpserver").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("sendusername").ToString()); mailMsg.To.Add(new System.Net.Mail.MailAddress(System.Configuration.ConfigurationSettings.AppSettings.Get("emailto").ToString())); mailMsg.Subject = "Enquiry Email from Web Visitor"; mailMsg.Body = strEmailText; mailMsg.IsBodyHtml = true; email.Send(mailMsg);Hiren999
Member
193 Points
64 Posts
Re: smtp mail problem
Sep 11, 2009 08:08 AM|LINK
hi harieis,
you get ur solution to following url :
http://forums.asp.net/t/1457421.aspx
and var is variable type that just use for storing data to result type
var is type that use like following :
var data = CustomerDetailBl.GetData(id);
var data = new string[];
that just type that contaion any type of object or anything....
bye
Mark as Answer if get ur solution
Thanks
( Software Engineer )
C#, ASP.NET, WPF, WCF,
SSRS, Crystal Report, SQL,
AJAX, MVC, SVN, VSS,
Telerik, Infragistics
waterduck
Member
15 Points
36 Posts
Re: smtp mail problem
Sep 12, 2009 01:31 AM|LINK
dear kipo....my visual studio doesn't support System.Net.Mail.SmtpClient...is there anyway else to do it?
waterduck
Member
15 Points
36 Posts
Re: smtp mail problem
Sep 14, 2009 02:44 AM|LINK
System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage(); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("sendusing").ToString())); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", System.Configuration.ConfigurationSettings.AppSettings.Get("smtpserver").ToString()); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("smtpconnectiontimeout").ToString())); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("smtpserverport").ToString())); message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("smtpauthenticate").ToString())); message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername",System.Configuration.ConfigurationSettings.AppSettings.Get("sendusername").ToString()); message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword",System.Configuration.ConfigurationSettings.AppSettings.Get("sendpassword").ToString()); message.From=System.Configuration.ConfigurationSettings.AppSettings.Get("sendusername").ToString(); message.To=System.Configuration.ConfigurationSettings.AppSettings.Get("emailto").ToString(); message.Subject="Enquiry Email from Web Visitor"; message.Body= strEmailText; //System.Web.Mail.SmtpMail.SmtpServer=System.Configuration.ConfigurationSettings.AppSettings.Get("smtpserver").ToString(); try { try { System.Web.Mail.SmtpMail.Send(message); } catch (Exception ex) { lblMessage.Text = "Error " + ex.InnerException.ToString(); } } catch(Exception ex) { lblMessage.Text = lblMessage.Text + "Error " + ex.ToString(); }Error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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)
How to solve this error code?
anirudha gup...
Member
581 Points
367 Posts
Re: smtp mail problem
Sep 14, 2009 04:26 AM|LINK
firstly i say that always use gmail becsause in asp.net gmail is better becuase other mail service provider not give a good service
so i use alwayse gogle mail service if you thing to send emil then take it my code
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System.Collections.Generic;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System.Web;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System.Web.UI;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System.Web.UI.WebControls;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">public partial class _Default : System.Web.UI.Page</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">{</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> protected void Page_Load(object sender, EventArgs e)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> protected void btn_Click(object sender, EventArgs e)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> // declare variable for sending mail</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> string tomail = this.txtto.Text;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> string subject = this.txtsub.Text;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> string body = this.txtbody.Text;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> // send a mail by gmail account</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> System.Net.Mail.MailMessage MyMailMessage =</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> new System.Net.Mail.MailMessage("anirudhakumar.gupta@gmail.com", tomail,</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">subject, body);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> MyMailMessage.IsBodyHtml = false;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //Proper Authentication Details need to be passed when sending email from gmail</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> System.Net.NetworkCredential mailAuthentication = new</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> System.Net.NetworkCredential("anirudhakumar.gupta@gmail.com", "zzxxccvv");</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //For different server like yahoo this details changes and you can</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //get it from respective server.</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //Enable SSL</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> mailClient.EnableSsl = true;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> mailClient.UseDefaultCredentials = false;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> mailClient.Credentials = mailAuthentication;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> try</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> mailClient.Send(MyMailMessage);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> catch (System.Net.Mail.SmtpException ex)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> Response.Write(ex.ToString());</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">}</div> <div></div>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("anirudhakumar.gupta@gmail.com", 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("anirudhakumar.gupta@gmail.com", "zzxxccvv"); //Smtp Mail server of Gmail is "smpt.gmail.com" 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("smtp.gmail.com", 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()); } } }waterduck
Member
15 Points
36 Posts
Re: smtp mail problem
Sep 14, 2009 05:42 AM|LINK
sorry...i don't have System.Net.Mail, i only able to get System.net
kipo
All-Star
16475 Points
2811 Posts
Re: smtp mail problem
Sep 14, 2009 06:07 AM|LINK
For what version of .NET Framework is your app designed?
waterduck
Member
15 Points
36 Posts
Re: smtp mail problem
Sep 14, 2009 07:21 AM|LINK
version 1.1.4322
kipo
All-Star
16475 Points
2811 Posts
Re: smtp mail problem
Sep 14, 2009 08:48 AM|LINK
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 article: http://uxuf.blogspot.com/2006/08/sending-mail-with-systemwebmail-net-11.html
waterduck
Member
15 Points
36 Posts
Re: smtp mail problem
Sep 15, 2009 02:09 AM|LINK
kipo, the same error occur using the source code provided.....
the last option i have is to embed vb codes in c#....is there a way to do it?