Problem sending mail through Gmail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AbusiveMeercat
    New Member
    • Jun 2010
    • 2

    #1

    Problem sending mail through Gmail

    Ugh this is so frustrating. This code doesn't work for some reason...Can anybody help me fix it?

    Code:
    class MainClass
    	{
    		public static void Main (string[] args)
    		{
    			MainClass mailman = new MainClass();
    			mailman.Mailer();
    		}
    		
    		public void Mailer ()
    		{
    		try
               {
                	MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com",465);
    
                    mail.From = new MailAddress("myemail@gmail.com");
                    mail.To.Add("otheremail@gmail.com");
                    mail.Subject = "Test Mail";
                    mail.Body = "This is for testing SMTP mail from GMAIL";
    
                    SmtpServer.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "password");
                    SmtpServer.EnableSsl = true;
    
                    SmtpServer.Send(mail);
    				Console.WriteLine("SENT");
               }
    		catch
    			{
    				Console.WriteLine("ERROR");
    			}
    			
    		}
    	}
    It doesnt even have an error. It sometimes says ERROR due to the catch statement but now it doesnt display anything just the console cursor thing blinks for ever...
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You have to enable smtp access per gmail account in their settings

    Comment

    • AbusiveMeercat
      New Member
      • Jun 2010
      • 2

      #3
      How can you do that in gmail.com? I dont use a outside email program...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Its under settings. google has a whole tutorial on it.

        Comment

        Working...