Created
July 13, 2017 04:32
-
-
Save chokelive/ab350a16ce7dc08eee46801ca320a64e to your computer and use it in GitHub Desktop.
Send Email Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Net.Mail; | |
using System.Collections; | |
public class SendMail | |
{ | |
public void send(string fromEN, ArrayList toEN, ArrayList ccEN, string subject, string body) | |
{ | |
int i; | |
string mailaddr = ""; | |
MailAddress mailFrm = null; | |
if (fromEN == "default") | |
{ | |
mailFrm = new MailAddress("[email protected]"); | |
} | |
else | |
{ | |
mailaddr = readMail(fromEN); | |
if (mailaddr != "") | |
{ | |
mailFrm = new MailAddress(mailaddr); | |
} | |
} | |
MailAddress mailTo; | |
MailAddress mailCc; | |
MailMessage mailMsg = new MailMessage(); | |
mailMsg.From = mailFrm; | |
for (i = 0; i < toEN.Count; i++) | |
{ | |
string emailTo = Convert.ToString(toEN[i]); | |
if (emailTo != "") //skip if somebody no email | |
{ | |
mailaddr = readMail(emailTo); | |
if (mailaddr != "") | |
{ | |
mailTo = new MailAddress(mailaddr); | |
mailMsg.To.Add(mailTo); | |
} | |
} | |
} | |
for (i = 0; i < ccEN.Count; i++) | |
{ | |
string emailCc = Convert.ToString(ccEN[i]); | |
if (emailCc != "") //skip if somebody no email | |
{ | |
mailaddr = readMail(emailCc); | |
if (mailaddr != "") | |
{ | |
mailCc = new MailAddress(mailaddr); | |
mailMsg.To.Add(mailCc); | |
} | |
} | |
} | |
mailMsg.CC.Add(mailFrm); | |
mailMsg.IsBodyHtml = true; | |
mailMsg.Subject = subject; | |
mailMsg.Body = body; | |
mailMsg.Body = mailMsg.Body + "<br/><br/><br/> Thank you <br/> HSA Training Record System <br/>http://172.17.66.220/JobTrack/"; | |
SmtpClient client = new SmtpClient("127.0.0.1"); | |
client.Credentials = CredentialCache.DefaultNetworkCredentials; | |
client.Send(mailMsg); | |
} | |
private string readMail(string en) | |
{ | |
string email = ""; | |
try | |
{ | |
myDB db = new myDB(); | |
string sql = "SELECT email FROM user WHERE en='"+en+"'"; | |
string tmpEmail = Convert.ToString(db.GetSingleData(sql)); | |
if (email != "") | |
{ | |
email = "," + tmpEmail; | |
} | |
else | |
{ | |
email = tmpEmail; | |
} | |
} | |
catch (Exception ex) | |
{ | |
} | |
return email; | |
} | |
//public string readmail(string en) | |
//{ | |
// string emailCompany = string.Empty; | |
// try | |
// { | |
// PrincipalContext domain = new PrincipalContext(ContextType.Domain); | |
// UserPrincipal QueryFilter = new UserPrincipal(domain); | |
// QueryFilter.EmployeeId = en; | |
// PrincipalSearcher ps = new PrincipalSearcher(QueryFilter); | |
// UserPrincipal user = (UserPrincipal)ps.FindOne(); | |
// emailCompany = user.EmailAddress; | |
// } | |
// catch | |
// { | |
// emailCompany = ""; | |
// } | |
// return emailWD; | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment