Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

Yesterday i had sent a mail using smtp.aol.com as host succesfully.but it was gone to spam mail to my friends mail id.

the coding i used is

C#
SmtpClient smtpClient = new SmtpClient();

        MailMessage message = new MailMessage();

        try
        {

            MailAddress fromAddress = new MailAddress("sanjithbtech@aol.com", "sanjith");

            message.From = fromAddress;//here you can set address

            message.To.Add("tamilselvank@i3itpeople.com");//here you can add multiple to

            message.Subject = "Feedback";//subject of email

            message.CC.Add("cc@site.com");//ccing the same email to other email address

            message.Bcc.Add(new MailAddress("bcc@site.com"));//here you can add bcc address

            message.IsBodyHtml = false;//To determine email body is html or not

            message.Body = @"Plain or HTML Text";

            smtpClient.Send(message);

        }

        catch (Exception ex)
        {

            //throw exception here you can write code to handle exception here

        }


        System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();

        //This object stores the authentication values

        System.Net.NetworkCredential basicCrenntial =
             new System.Net.NetworkCredential("sanjithbtech@aol.com", "bmbitsba");

        mailClient.Host = "smtp.aol.com";

        mailClient.UseDefaultCredentials = false;

        mailClient.Credentials = basicCrenntial;

        mailClient.Send(message);
        lblStatus.Text = " Send Successfully!";


but when i sending through the same coding in the morning,it was showing the following error as

Server Error in '/' Application.
The remote certificate is invalid according to the validation procedure.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

Source Error:

Line 154:        objSmtpClient.Credentials = new System.Net.NetworkCredential("sanjithbtech@aol.com", "bmbitsba");
Line 155:
Line 156:        objSmtpClient.Send(objEmail);
Line 157:
Line 158:


Source File: c:\inetpub\vhosts\cegonsoftfaq.com\httpdocs\ContactUs.aspx.cs    Line: 156

Stack Trace:

[AuthenticationException: The remote certificate is invalid according to the validation procedure.]
   System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) +1646387
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +6153133
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +53
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +120
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +85
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +61
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +53
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +120
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +85
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +61


Whats the problem with this coding.what port i have to use.or any other solution.
Posted
Updated 10-Oct-11 20:33pm
v4
Comments
Sazzad Hossain 11-Oct-11 2:47am    
i hope that's not ur actual password u pasted on ur code block :)

Add this to your webconfig :
XML
<system.net>
        <mailSettings>
            <smtp deliveryMethod="Network" from="sanjithbtech@aol.com">
                <network host="smtp.aol.com" userName="sanjithbtech@aol.com" password="bmbitsba" port="25"/>
            </smtp>
        </mailSettings>
    </system.net>


Then Use your hotmail account in code behind :

System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
 
            //This object stores the authentication values
 
            System.Net.NetworkCredential basicCrenntial =
                  new System.Net.NetworkCredential("yout hotmail email", "password");
 
            mailClient.Host = "smtp.live.com";
 
            mailClient.UseDefaultCredentials = true;
 
            mailClient.Credentials = basicCredential;
 mailClient.port=587;
            mailClient.Send(message);
            lblStatus.Text = " Send Successfully!";

Hope it work....
Good Luck :)
 
Share this answer
 
v2
Comments
Member 7976636 11-Oct-11 3:13am    
hi again the following error s coming

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'System.Net.Mail.SmtpClient' does not contain a definition for 'port' and no extension method 'port' accepting a first argument of type 'System.Net.Mail.SmtpClient' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 127:
Line 128: mailClient.Credentials = basicCrenntial;
Line 129: mailClient.port = 587;
Line 130: mailClient.Send(message);
Line 131: lblStatus.Text = " Send Successfully!";
Use the code in this link it will work

How to send email through asp.net[^]
 
Share this answer
 
C#
SmtpClient serverobj = new SmtpClient();
                        serverobj.Credentials = new NetworkCredential("anilmeets4u@gmail.com", "yourpassword");
                        serverobj.Port = 587;
                        serverobj.Host = "smtp.gmail.com";
                        serverobj.EnableSsl = false;
                        obj = new System.Net.Mail.MailMessage();
                        obj.From = new MailAddress("anilmeets4u@gmail.com", "AgileLearning.com", System.Text.Encoding.UTF8);

                        obj.To.Add(ds.Tables[0].Rows[i]["strEmail"].ToString());
                        obj.Priority = System.Net.Mail.MailPriority.High;
                        obj.Subject = "Regarding  TechnicalProblem";
                        string date = DateTime.Now.ToString();
                        obj.Body = "Your Technical Problem will be Rectified Within 24Hours";
                        serverobj.Send(obj);



Hope this works!

Regards,

Anilkumar.D
 
Share this answer
 
v2
I think this problem with SSL certificate as you are getting following error

Quote:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.


I think your problem will solved by following code.

C#
System.Net.ServicePointManager.ServerCertificateValidationCallback += 
    (s, cert, chain, sslPolicyErrors) => true;

Source is : asp.net - Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure - Stack Overflow[^]


You can check following links also
.net - Could not establish trust relationship for the SSL/TLS secure channel with subject alternative name certificate - Stack Overflow[^]

The remote certificate is invalid according to the validation procedure &ndash; Server Density[^]

Hope this will help you. Good luck :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900