ASP.NET 1.1 - Gmail 이용해서 메일 보내기
2014. 7. 23. 13:58
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 using System.Web.Mail;public static bool sendMail(Message message){bool result = false;MailMessage oMsg = new MailMessage();try{try{oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com");oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", true);oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "userid@gmail.com");oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "passoword");// DebugoMsg.To = "anynone@domain.com";oMsg.From = "userid@gmail.com";oMsg.Subject = "Test mail";oMsg.BodyFormat = MailFormat.Text;oMsg.Priority = MailPriority.High;oMsg.Body = "This is a test message.";System.Console.WriteLine(oMsg.To);System.Console.WriteLine(oMsg.From);System.Console.WriteLine(oMsg.Subject);System.Console.WriteLine(oMsg.Body);try{SmtpMail.SmtpServer = "smtp.gmail.com";SmtpMail.Send(oMsg);result = true;}catch (System.Web.HttpException exp){result = false;System.Console.WriteLine("{0}", exp.Message);System.Console.WriteLine("Here is the full message output.");System.Console.WriteLine("{0}", exp.ToString());}}catch (System.IndexOutOfRangeException){result = false;System.Console.WriteLine("Usage error.");}}catch (System.Exception exp){result = false;System.Console.WriteLine("Unknown Exception occurred {0}.", exp.Message);System.Console.WriteLine("Here is the full message output.");System.Console.WriteLine("{0}", exp.ToString());}return result;}cs