I am having an issue in my project trying to developing a mail webservice but getting an error transport failed to connect to server.
Below is the code...

protected void btnsubmit_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.From = "ruchi.dubey18@gmail.com";
        mail.To = txtTo.Text.Trim();
        mail.Subject = txtSubject.Text.Trim();
        mail.Body = txtBody.Text.Trim();
        SmtpMail.SmtpServer = "smtp.gmail.com";
        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "ruchi.dubey18@gmail.com");
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "jaishreek");

 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "2");
        SmtpMail.Send(mail);
    }

please help its urgent...

You need to set username/password, and other parameters in order to send an email.

For instance,

try
{
    System.Net.Mail.MailMessage mm=new System.Net.Mail.MailMessage("to@aaa.com","aaa@gmail.com");

   mm.Subject = "Subject details";
   mm.Body = "Sample...";

   SmtpClient sc = new System.Net.Mail.SmtpClient();
   System.Net.NetworkCredential auth = new  System.Net.NetworkCredential("your@gmail.com", "your_pass");

   sc.Host = "smtp.googlemail.com";
   sc.Port = 587;
   sc.UseDefaultCredentials = false;
   sc.Credentials = auth;
   sc.EnableSsl = true;
   sc.Send(mm);

   Response.Write( "your mail has been sent successfully..");
   }catch (Exception ex)
    {
            Response.Write(ex);
     }
.....
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.