Commit 0f5aa9a7f27e3e30ad2244cb8002f656c59e5679
1 parent
93fecc81
report
Showing
1 changed file
with
123 additions
and
123 deletions
400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs
1 | -using System; | ||
2 | -using System.Collections.Generic; | ||
3 | -using System.Linq; | ||
4 | -using System.Web; | ||
5 | -using System.Configuration; | ||
6 | -using System.Collections; | ||
7 | -using System.Xml; | ||
8 | -using System.Text; | ||
9 | -using System.IO; | 1 | +using System; |
2 | +using System.Collections.Generic; | ||
3 | +using System.Linq; | ||
4 | +using System.Web; | ||
5 | +using System.Configuration; | ||
6 | +using System.Collections; | ||
7 | +using System.Xml; | ||
8 | +using System.Text; | ||
9 | +using System.IO; | ||
10 | using System.Net.Mail; | 10 | using System.Net.Mail; |
11 | -using log4net; | ||
12 | - | ||
13 | -namespace AIAHTML5.API.Utility | ||
14 | -{ | ||
15 | - | ||
16 | - public class EmailUtility | ||
17 | - { | ||
18 | - public string sFromAddress { get; set; } | ||
19 | - public List<string> sToAddresses { get; set; } | ||
20 | - public List<string> sBccAddresses { get; set; } | ||
21 | - public string sHostName { get; set; } | ||
22 | - public string sSubject { get; set; } | ||
23 | - public int iPort { get; set; } | ||
24 | - public bool bEnableSsl { get; set; } | ||
25 | - public string sUserName { get; set; } | ||
26 | - public string sPassword { get; set; } | ||
27 | - public bool bIsBodyHtml { get; set; } | ||
28 | - public List<Attachment> sAttachments { get; set; } | ||
29 | - public string sBodyText { get; set; } | ||
30 | - public AlternateView sAlternateView { get; set; } | ||
31 | - | ||
32 | - public void SendMail(MailMessage mm) | ||
33 | - { | ||
34 | - SmtpClient smtp = new SmtpClient(); | ||
35 | - smtp.Host = ConfigurationManager.AppSettings["SMTPAddress"]; | ||
36 | - smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]); | ||
37 | - System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]); | ||
38 | - smtp.Credentials = NetworkCred; | ||
39 | - smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]); | ||
40 | - | ||
41 | - smtp.Send(mm); | ||
42 | - } | ||
43 | - | ||
44 | - public void SendSmtpEmail() | 11 | +using log4net; |
12 | + | ||
13 | +namespace AIAHTML5.API.Utility | ||
14 | +{ | ||
15 | + | ||
16 | + public class EmailUtility | ||
17 | + { | ||
18 | + public string sFromAddress { get; set; } | ||
19 | + public List<string> sToAddresses { get; set; } | ||
20 | + public List<string> sBccAddresses { get; set; } | ||
21 | + public string sHostName { get; set; } | ||
22 | + public string sSubject { get; set; } | ||
23 | + public int iPort { get; set; } | ||
24 | + public bool bEnableSsl { get; set; } | ||
25 | + public string sUserName { get; set; } | ||
26 | + public string sPassword { get; set; } | ||
27 | + public bool bIsBodyHtml { get; set; } | ||
28 | + public List<Attachment> sAttachments { get; set; } | ||
29 | + public string sBodyText { get; set; } | ||
30 | + public AlternateView sAlternateView { get; set; } | ||
31 | + | ||
32 | + public void SendMail(MailMessage mm) | ||
33 | + { | ||
34 | + SmtpClient smtp = new SmtpClient(); | ||
35 | + smtp.Host = ConfigurationManager.AppSettings["SMTPAddress"]; | ||
36 | + smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]); | ||
37 | + System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]); | ||
38 | + smtp.Credentials = NetworkCred; | ||
39 | + smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]); | ||
40 | + | ||
41 | + smtp.Send(mm); | ||
42 | + } | ||
43 | + | ||
44 | + public void SendSmtpEmail() | ||
45 | { | 45 | { |
46 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | 46 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
47 | - logger.Debug("inside SendSmtpEmail"); | ||
48 | - | ||
49 | - try | ||
50 | - { | ||
51 | - MailMessage sMail = new MailMessage(); | ||
52 | - SmtpClient SmtpServer = new SmtpClient(sHostName); | ||
53 | - string recipientEmailAddress = string.Empty; | ||
54 | - | ||
55 | - | ||
56 | - if (sToAddresses != null) | ||
57 | - { | ||
58 | - foreach (var sItem in sToAddresses) | ||
59 | - { | 47 | + logger.Debug("inside SendSmtpEmail"); |
48 | + | ||
49 | + try | ||
50 | + { | ||
51 | + MailMessage sMail = new MailMessage(); | ||
52 | + SmtpClient SmtpServer = new SmtpClient(sHostName); | ||
53 | + string recipientEmailAddress = string.Empty; | ||
54 | + | ||
55 | + | ||
56 | + if (sToAddresses != null) | ||
57 | + { | ||
58 | + foreach (var sItem in sToAddresses) | ||
59 | + { | ||
60 | sMail.To.Add(sItem); | 60 | sMail.To.Add(sItem); |
61 | - logger.Debug("sToAddresses= " + sItem); | ||
62 | - } | ||
63 | - } | ||
64 | - | ||
65 | - if (sBccAddresses != null) | ||
66 | - { | ||
67 | - foreach (var sItem in sBccAddresses) | ||
68 | - { | 61 | + logger.Debug("sToAddresses= " + sItem); |
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + if (sBccAddresses != null) | ||
66 | + { | ||
67 | + foreach (var sItem in sBccAddresses) | ||
68 | + { | ||
69 | sMail.Bcc.Add(sItem); | 69 | sMail.Bcc.Add(sItem); |
70 | - logger.Debug("sBccAddresses= " + sItem); | ||
71 | - | ||
72 | - } | ||
73 | - } | ||
74 | - | ||
75 | - sMail.IsBodyHtml = bIsBodyHtml; | ||
76 | - | ||
77 | - if (sAlternateView != null) | ||
78 | - { | 70 | + logger.Debug("sBccAddresses= " + sItem); |
71 | + | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + sMail.IsBodyHtml = bIsBodyHtml; | ||
76 | + | ||
77 | + if (sAlternateView != null) | ||
78 | + { | ||
79 | sMail.AlternateViews.Add(sAlternateView); | 79 | sMail.AlternateViews.Add(sAlternateView); |
80 | - logger.Debug("sAlternateView= " + sAlternateView); | ||
81 | - | ||
82 | - } | ||
83 | - else | ||
84 | - { | 80 | + logger.Debug("sAlternateView= " + sAlternateView); |
81 | + | ||
82 | + } | ||
83 | + else | ||
84 | + { | ||
85 | sMail.Body = sBodyText; | 85 | sMail.Body = sBodyText; |
86 | - logger.Debug("sMail.Body= " + sBodyText); | ||
87 | - | ||
88 | - } | ||
89 | - | 86 | + logger.Debug("sMail.Body= " + sBodyText); |
87 | + | ||
88 | + } | ||
89 | + | ||
90 | sMail.Subject = sSubject; | 90 | sMail.Subject = sSubject; |
91 | - logger.Debug("sMail.Subject= " + sSubject); | ||
92 | - | ||
93 | - if (sAttachments != null) | ||
94 | - { | ||
95 | - foreach (var sItem in sAttachments) | ||
96 | - { | 91 | + logger.Debug("sMail.Subject= " + sSubject); |
92 | + | ||
93 | + if (sAttachments != null) | ||
94 | + { | ||
95 | + foreach (var sItem in sAttachments) | ||
96 | + { | ||
97 | sMail.Attachments.Add(sItem); | 97 | sMail.Attachments.Add(sItem); |
98 | - logger.Debug("sAttachments= " + sAttachments); | ||
99 | - | ||
100 | - | ||
101 | - } | 98 | + logger.Debug("sAttachments= " + sAttachments); |
99 | + | ||
100 | + | ||
101 | + } | ||
102 | } | 102 | } |
103 | - logger.Debug("sUserName= " + sUserName + ", sPassword= " + sPassword); | ||
104 | - | ||
105 | - SmtpServer.Port = iPort; | ||
106 | - SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword); | ||
107 | - SmtpServer.EnableSsl = bEnableSsl; | ||
108 | - | ||
109 | - using (MailMessage mm = new MailMessage(sFromAddress, sMail.To.ToString())) | ||
110 | - { | ||
111 | - mm.Subject = sSubject; | ||
112 | - mm.IsBodyHtml = bIsBodyHtml; | ||
113 | - | ||
114 | - if (sAlternateView != null) | ||
115 | - { | ||
116 | - mm.AlternateViews.Add(sAlternateView); | ||
117 | - } | ||
118 | - else | ||
119 | - { | ||
120 | - mm.Body = sBodyText; | ||
121 | - } | ||
122 | - | ||
123 | - mm.IsBodyHtml = true; | 103 | + logger.Debug("sUserName= " + sUserName + ", sPassword= " + sPassword); |
104 | + | ||
105 | + SmtpServer.Port = iPort; | ||
106 | + SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword); | ||
107 | + SmtpServer.EnableSsl = bEnableSsl; | ||
108 | + | ||
109 | + using (MailMessage mm = new MailMessage(sFromAddress, sMail.To.ToString())) | ||
110 | + { | ||
111 | + mm.Subject = sSubject; | ||
112 | + mm.IsBodyHtml = bIsBodyHtml; | ||
113 | + | ||
114 | + if (sAlternateView != null) | ||
115 | + { | ||
116 | + mm.AlternateViews.Add(sAlternateView); | ||
117 | + } | ||
118 | + else | ||
119 | + { | ||
120 | + mm.Body = sBodyText; | ||
121 | + } | ||
122 | + | ||
123 | + mm.IsBodyHtml = true; | ||
124 | SendMail(mm); | 124 | SendMail(mm); |
125 | - logger.Debug("after sending email"); | ||
126 | - } | ||
127 | - | ||
128 | - } | ||
129 | - catch (Exception ex) | 125 | + logger.Debug("after sending email"); |
126 | + } | ||
127 | + | ||
128 | + } | ||
129 | + catch (Exception ex) | ||
130 | { | 130 | { |
131 | - logger.Fatal("exception in SendSmtpEmail.msg= " + ex.Message + ", stacktarce= " + ex.StackTrace); | ||
132 | - throw ex; | ||
133 | - } | ||
134 | - } | ||
135 | - } | 131 | + logger.Fatal("exception in SendSmtpEmail.msg= " + ex.Message + ", stacktarce= " + ex.StackTrace); |
132 | + throw ex; | ||
133 | + } | ||
134 | + } | ||
135 | + } | ||
136 | } | 136 | } |
137 | \ No newline at end of file | 137 | \ No newline at end of file |