1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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");
 
     // Debug
     oMsg.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


+ Recent posts