Wednesday 24 July 2013

The best overload method match for 'System.Net.NetworkCredential.NetworkCredential(string,string)' has some invalid arguments

The best overload method match for 'System.Net.NetworkCredential.NetworkCredential(string,string)' has some invalid arguments


Solution: I Had Taken

varfromAddress = "myemailid@gmail.com";// Gmail Credentials ID From Which The Mail Id To Be Send
var toAddress = YourEmail.Text.ToString();// Mail Id That Mail Has To Be Send
       
const var fromPassword = "mypassword";//Password of our gmail address
        // Passing the values and make a email formate to display
        stringsubject = YourSubject.Text.ToString();
        stringbody = "From: " + YourName.Text + "\n";
         // smtp settings
        varsmtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
         smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object

        smtp.Send(fromAddress, toAddress, subject, body);

I Replaced The var with string And Create Smpt Object With SmptClient

string fromAddress = "myemailid@gmail.com";// Gmail Credentials ID From Which The Mail Id To Be Send
string toAddress = YourEmail.Text.ToString();// Mail Id That Mail Has To Be Send
       
const string fromPassword = "mypassword";//Password of our gmail address
        // Passing the values and make a email formate to display
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
         // smtp settings
       SmtpClient smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
         smtp.Credentials = new NetworkCredential(fromAddressfromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object

        smtp.Send(fromAddress, toAddress, subject, body);

Now It Works Correct...

No comments:

Post a Comment

Note: only a member of this blog may post a comment.