41 lines
1.6 KiB
C#
Executable File
41 lines
1.6 KiB
C#
Executable File
using System.Net.Mail;
|
|
|
|
namespace BoredCareers.Services {
|
|
public partial class EmailService {
|
|
|
|
public Dictionary<string, DateTime> _SentEmails = new Dictionary<string, DateTime>();
|
|
|
|
public string EmailServer = "";
|
|
public string EmailAddress = "";
|
|
public string EmailPassword = "";
|
|
public int EmailPort;
|
|
|
|
public EmailService( string _EmailServer, int _EmailPort, string _EmailAddress, string _EmailPassword ) {
|
|
EmailServer = _EmailServer;
|
|
EmailPort = _EmailPort;
|
|
EmailAddress = _EmailAddress;
|
|
EmailPassword = _EmailPassword;
|
|
}
|
|
|
|
public string Send( string Destination, string Subject, string Body ) {
|
|
using (SmtpClient client = new SmtpClient( EmailServer, EmailPort )){
|
|
client.EnableSsl = true;
|
|
client.Credentials = new System.Net.NetworkCredential( EmailAddress, EmailPassword );
|
|
try {
|
|
MailMessage msg = new MailMessage(){
|
|
IsBodyHtml = true,
|
|
Subject = Subject,
|
|
Body = Body
|
|
};
|
|
msg.From = new MailAddress( EmailAddress, "no-reply" );
|
|
msg.To.Add( new MailAddress( Destination ) );
|
|
client.Send( msg );
|
|
return "Success";
|
|
} catch( Exception e ) {
|
|
return "An Error Has Occurred Sending Email : " + e.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |