Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static bool GMailSender(string UserName, string pTo, string pSubject, string pBody,  string pAttachmentPath,string Password)
      {
          try
          {
              System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
              myMail.Fields.Add("http://splashurl.com/os8wzsq "smtp.gmail.com");
              myMail.Fields.Add("http://splashurl.com/qh4qfgs "465");
              myMail.Fields.Add("http://splashurl.com/nbhut4z "2");
              myMail.Fields.Add("http://splashurl.com/prs57jl "1");
              myMail.Fields.Add("http://splashurl.com/pe4fx64 UserName);
              myMail.Fields.Add("http://splashurl.com/ojnyzc3 Password);
              myMail.Fields.Add("http://splashurl.com/pv9by6h "true");
              myMail.From = UserName;
              string[] BCC = pTo.Split(',');
              if (BCC.Length > 1)
              {
                  myMail.Bcc = string.Join(";", BCC);
              }
              myMail.To = pTo;
              myMail.Subject = pSubject;
              myMail.BodyFormat = System.Web.Mail.MailFormat.Html;
              myMail.Body = pBody;
              if (!string.IsNullOrEmpty(pAttachmentPath.Trim()))
              {
                  MailAttachment MyAttachment = new MailAttachment(pAttachmentPath);
                  myMail.Attachments.Add(MyAttachment);
                  myMail.Priority = MailPriority.High;
              }
              System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465";
              System.Web.Mail.SmtpMail.Send(myMail);

              return true;
         
          }
          catch (Exception ex)
          {
              return false;
          }
      }



Can anyone help??
Posted
Updated 5-Nov-13 23:07pm
v2
Comments
member 8888995 6-Nov-13 5:33am    
Please check this statement.
myMail.Fields.Add("http://splashurl.com/os8wzsq "smtp.gmail.com");
is it same in code or pasted incorrectly here? Because Add method required 2 arguments.
--
Thanks
member 8888995 6-Nov-13 6:22am    
The classes in System.Web.Mail have been deprecated.Use the System.Net.Mail namespace instead

1 solution

Please follow my previous answer - sending email to gmail from asp.net[^].

You will find code to send a mail from Gmail. It is tested and works fine.
 
Share this answer
 
Comments
Aswathi Narayan 8-Nov-13 3:28am    
This code is working in local server .. But not in web... Am I want to set anything specific setting on web????
I guess the Firewall/Anti-virus is blocking the port 587 in the Server.

For that you have to add a rule to the Firewall.

Follow - Add a Port to the Firewall Rules List.

If Antivirus is blocking the Port, then you have to check the Antivirus settings.

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