.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

C# sending smtp mails failed

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :WPF

Hi All,

I am trying to figure out what suddenly happened to my project. It was working fine but now its not.

this is stack trace

   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at WindowsKeyloggerTool.frmSettings.SendTestMail(String message) in c:\users\avinash\documents\visual studio 2010\Projects\WindowsKeyloggerTool\WindowsKeyloggerTool\frmSettings.cs:line 103
   at WindowsKeyloggerTool.frmSettings.ValidateUserCredentials() in c:\users\avinash\documents\visual studio 2010\Projects\WindowsKeyloggerTool\WindowsKeyloggerTool\frmSettings.cs:line 75

and inner exception

Unable to find an entry point named 'EnumerateSecurityPackagesW' in DLL 'security.dll'.

   at System.Net.UnsafeNclNativeMethods.SafeNetHandles_SECURITY.EnumerateSecurityPackagesW(Int32& pkgnum, SafeFreeContextBuffer_SECURITY& handle)
   at System.Net.SafeFreeContextBuffer.EnumeratePackages(SecurDll Dll, Int32& pkgnum, SafeFreeContextBuffer& pkgArray)
   at System.Net.SSPISecureChannelType.EnumerateSecurityPackages(Int32& pkgnum, SafeFreeContextBuffer& pkgArray)
   at System.Net.SSPIWrapper.EnumerateSecurityPackages(SSPIInterface SecModule)

Please help you. I am no brainer here.

View Complete Post

More Related Resource Links

smtp server 5.1 in xp not sending emails


hi iam using asp.net 2.0 with c#.net.

in my application when client completes its shopping email will goes to user this works fine when there is internet connection is working fine,
if  there is some problem  in internet connection if one mail stops then all the mails will be stopped even now internet works fine,

how to resend the emails using smtp server, is there any option to resend the emails automatically when internet works fine.

can you give example which helps me.

smtp is noe sending email instantly,it makes a Queue in my local system

I am using a  smtp to send email from asp.net (C#)code.it sending some email instantly but many of email is making a queue in my Inetpub folder at local system.what could be the issue ? please help me to get rid from it.ThankxArvind

Email Sending Failed

I have email sending option in my ASP.net application(Developed in visual web developer2008 on XP), i am sending the mails with 3 attachements without any problems.I have launched same project in another branch(On windowsXP Machine), from here i am not succeeded to send mails.Following error was througing..My smtp server is smtp.mailserver.com. Server Error in '/' Application.--------------------------------------------------------------------------------No connection could be made because the target machine actively refused it Code Sending mail successfully from my local machineProtected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click        Dim smtp As New System.Net.Mail.SmtpClient()        Dim smail As New System.Net.Mail.MailMessage        lblMessage.Text = ""        If DDReceiver.Text = "" Then            MsgBox("Enter Valid E-Mail Address")        Else            smail.To.Add(New System.Net.Mail.MailAddress(DDReceiver.Text))        End If     

sending email in asp.net A connection attempt failed because the connected party did not properly re

Hi everyone,   I am sending email , but getting this error on this line smtpClient.Send(mail); "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond IP adress ...   MailMessage mail = new MailMessage(); mail.To.Add( "test@mywebname.com"); mail.From = new MailAddress(txtEmail.Text); mail.Subject = "Testing Email";   string Body = "Demo Email trial"; mail.Body = Body; mail.IsBodyHtml = true;   SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = "mail.mywebname.com"; smtpClient.Credentials = new System.Net.NetworkCredential("test@mywebname.com", "passwd"); smtpClient.Send(mail);   plz help me

What will be the correct smtp settings for sending out email from an asp.net website to gmail's bus

Hi,I have setup a gmail's business account for my company.Now I want to receive all the emails like ContactUs, Qoute Email, etc from my website to that account i.e. info@mydomainname.com I have added the following smtp settings behind my web formsSmtpClient smtpClient = new SmtpClient("localhost",25); //Providing Network credentials smtpClient.Credentials = new System.Net.NetworkCredential("quote@mydomainname.com", "password"); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mail = new MailMessage(); //HTML Mail Format mail.IsBodyHtml = false; //Setting Form , To and CC mail.From = new MailAddress("quote@mydomainname.com", "My Web Site"); mail.To.Add(new MailAddress("info@mydomainname.com")); This code gives me feedback "email has successful sent"  but it does not send any email to info@mydomainname.comCan anyone let me know what will be the correct smtp settings for sending out emails to gmail's business accounts?Regards,Dazy

Sending email via SmtpClient() not working with smtp.gmail.com :(

Help I cannot seem to send an email via my gmail account using "C#" why not?   <system.net> <mailSettings> <smtp deliveryMethod="Network" from="ian.coetzer@gmail.com"> <network host="smtp.gmail.com" port="587" enableSsl ="true" defaultCredentials ="false" password ="xxxxxx" userName ="ian.coetzer@gmail.com"></network> </smtp> </mailSettings> </system.net> SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { message.To.Add(emailTo); message.Subject = ""; message.Body = GetEmailBody(userName, password, url); smtpClient.Send(message); return true; } catch(Exception ex) { throw new ApplicationException("Could not send notification.", ex); }   I.W Coetzer

sending email using IIS smtp service


 I am working on an email that someone will send from one of our main sites requesting an account password.  I am using System.Net.Mail.MailMessage to create the email and then sending it using System.Net.Mail.SmtpClient.  Below is my code: 

	Public Function sendEmail(ByVal address As String) As String
		Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
		mailMessage.To.Add(New System.Net.Mail.MailAddress("emailAddress"))
		mailMessage.From = (New System.Net.Mail.MailAddress(address))
		Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
		Catch ex As Exception
			Throw New ApplicationException("Data Error", ex)
		End Try
	End Function

	Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
	End Sub

Then in my web.config file I have the following

				<network host="cook.CMAP.public" port="25" 
It all looks like it is right bu

smtp sending email twice.


I am using .net membership functionality, The problem is on forget password page it send two emails to the user , any idea why?

I am using Windows 2008 Server.

Imports System.Net.Mail

Partial Class registration_ForgotPassword
    Inherits System.Web.UI.Page
    Protected Sub btnSendPassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendPassword.Click
    End Sub

#Region "SendForgotPasswordEmail"
    Private Sub SendForgotPasswordEmail()
        Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()

        Dim message As String = String.Empty
        Dim emailTo As String = txtEmail.Text

        Dim username As String
        Dim password As String
        password = ""

        Dim list As MembershipUserCollection
        list = Membership.FindUsersByEmail(emailTo)

        If list.Count > 0 Then
            username = Membership.GetUserNameByEmail(emailTo)
            password = list(username).ResetPassword()

            Dim msg As String = ""
            msg = "Your password is " + password

            msg = msg & "</br> As this is a temporary password please immediately change your password after login."
            message = msg
            Dim objmm As New MailMessag

Testing Emails Sending (SMTP) under IIS7 Express (WebMatrix)


Hi there,

I don't have web server account yet so I must test my applications with the Web Development Server under VS 2010 with C# but I read that I couldn't send emails under that server but I also read that I can send email with IIS7 Express and that's the main reason why I've install Webmatrix. Maybe someone can confirm this.

So for the moment I am redirecting my emails into a local folder and it is working perfectly.

Here is part of the code I've add to the Web.Config for doing that.

      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="D:\Temp"/>


As you can see I am redirecting the emails to the D:\temp

The following code for sending emails comes 
from the videos of JOE STAGNER at Microsoft
but beware there is a few typing errors in 
his video like missing > " 


Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

WebMatrix conversion failed when converting from a character string to uniqueidentifier?


I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

Sending a File Using Email Helper in WebPages/Razor


Note: This is particularly with respect to Email Helper in WebPages/Razor. Please don't post links using System.Net.Mail object.

Following this tutorial: http://www.asp.net/webmatrix/tutorials/9-adding-email-to-your-website

Under "Sending a File Using Email" section what exactly is the code trying to do.

1: The SendFile.cshtml does not have any option to select file.

2: ProcessFile.cshtml is running fine. I am getting the email but no attachement.

I tried changing fileAttachment input to type="file" but not file is being sent to my email. I just get the message send in body.

Question: How exactly this file attachment works using Email Helper in WebPages.

Failed to create AppDomain


Recently updated my system to use Visual Studio 2010, and projects will no longer compile. All of them give the error "Failed to create AppDomain." Intellisense does not work either (except for standard HTML tags), and individual pages will also not compile.

Points of note:

  • All sites are hosted on UNC shares (although it doesn't work on a new site created on local drive either)
  • Language is mostly C#
  • No explicit code is creating AppDomain objects
  • Sites compiled fine under both VS 2005 and 2008 both before and after VS 2010 installation
  • Sites compile and run fine from the IIS server on the remote machines (one IIS 6, one IIS 7)

Things I've tried (some obviously shouldn't have any bearing on it, but I've tried just about everything that anyone suggested on any forum I could find, most of which seemed to apply to IIS, not VS):

  • renaming/deleting security.config
  • running caspol -reset
  • re-registering asp.net: aspnet_regiis.exe -ua / aspnet_regiis.exe -i
  • removing VS 2005, 2008, 2010, and then re-installing just VS 2010
  • adding the UNC path to the local intranet zone (internet options control panel)
  • adding the UNC path to LocalIntranet_Zone in the ASP.Net 2.0 control panel (runtime security policy/machine/al

helped needed: ASP LDAP authentication failed in IE 8


I use the following code to do the user authentication through Active Directory using LDAP.

entry = new DirectoryEntry("LDAP://" + server, user_name, password);
if (!string.IsNullOrEmpty(entry.Name))
EmployeeNetId = entry.Username.Substring(0, 3);

// Retrieve EmployeeId, and Employee Full Name
EmployeeId = -1;

It works for Chrome, Firefox with no problem. But with IE 8, it works sometimes, and failed on some computers. When it failed, I figured that I need to check SSL 2.0 in IE 8 Internet Options.  It's weird because in those computers that IE 8 works, SSL 2.0 is also unchecked.

Am I using some deprecated method? Or How do I specifiy the SSL version options in the LDAP connection?

WCF The Security Support Provider Interface (SSPI) negotiation failed


I am using a wcf service that I created, when both hosting machine and the client machine are on the same domain everything works just fine. When I publish the client app to the webserver in the DMZ I am getting the following error:

SOAP security negotiation with '' for   
'' failed. See inner exception  
for more details.The Security Support Provider Interface (SSPI) negotiation failed.

Here is my service main where I set up the service


 Uri baseAddress = new Uri("Http://");
      ServiceHost selfHost = new ServiceHost(typeof(QBService), baseAddress);


Intermittant error: "A connection attempt failed because the connected party did not properly respon



I'm having a doozy of a problem, and can't find a solution.  I have a WFC Web Service installed to a pair of servers, and accessed through a load balancer.  I am accessing the service from an ASP.NET client app, also via WCF.  The Client is not load balanced.

I'm getting an intermittant error:

(Inner Most Exception) System.Net.Sockets.SocketException:  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond x.x.x.x:80

(Middle Exception) System.Net.WebException: Unable to connect to the remote server

(Outer Exception) System.ServiceModel.EndpointNotFoundException:  Could not connect to http://<MYSite>/<MYApp>/<MYService>.svc. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond x.x.x.x:80.

I can reproduce this error with about 20% reliability if I execute the exact same page request on the client from 2 browsers at the same time.  When the problem occurs, the successful p

Security negotiation failed because the remote party did not send back a reply in a timely manner. T



Dear All i have created one simple service

like this

namespace WcfService2
        public class Service1 : IService1
        public string ShowEmpName(string strFirstName, string strLastName)
            return strFirstName + strLastName;

after executing in .net command promt i got 2 files

service.cs & output.config

after that i create one class file like this

namespace WcfService2
    public class clientcs

        static void Main(string[] args)
            Service1Client client = new Service1Client();
            string strResult = client.ShowEmpName("Pradeep", "Deokar");

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend