111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Net.Mail;
|
|
using System.Net;
|
|
using OpenPOP.POP3;
|
|
|
|
namespace SafeNetLib
|
|
{
|
|
public class EmailServerSSL
|
|
{
|
|
private POPClient popClient;
|
|
private string serverIP;
|
|
private int port;
|
|
private string loginNAme;
|
|
private string password;
|
|
|
|
//constructor
|
|
public EmailServerSSL(string _serverIP, string _port, string _logName, string _pass)
|
|
{
|
|
bool result = Int32.TryParse(_port, out port);
|
|
if (!result)
|
|
{
|
|
Console.WriteLine("Email port not numeric, error in EmailServerSSL constructor.");
|
|
return;
|
|
}
|
|
|
|
serverIP = _serverIP;
|
|
loginNAme = _logName;
|
|
password = _pass;
|
|
|
|
popClient = new POPClient();
|
|
popClient.AuthenticationBegan += new EventHandler(popClient_AuthenticationBegan);
|
|
popClient.AuthenticationFinished += new EventHandler(popClient_AuthenticationFinished);
|
|
popClient.CommunicationBegan += new EventHandler(popClient_CommunicationBegan);
|
|
popClient.CommunicationOccured += new EventHandler(popClient_CommunicationOccured);
|
|
popClient.CommunicationLost += new EventHandler(popClient_CommunicationLost);
|
|
popClient.MessageTransferBegan += new EventHandler(popClient_MessageTransferBegan);
|
|
popClient.MessageTransferFinished += new EventHandler(popClient_MessageTransferFinished);
|
|
}
|
|
#region popCLient events
|
|
private void AddEvent(string strEvent)
|
|
{
|
|
/*
|
|
lstEvents.Items.Add(strEvent);
|
|
lstEvents.SelectedIndex = lstEvents.Items.Count - 1;
|
|
*/
|
|
//Console.WriteLine("popClient event = " +strEvent);
|
|
}
|
|
|
|
private void popClient_CommunicationBegan(object sender, EventArgs e)
|
|
{
|
|
AddEvent("CommunicationBegan");
|
|
}
|
|
|
|
private void popClient_CommunicationOccured(object sender, EventArgs e)
|
|
{
|
|
AddEvent("CommunicationOccured");
|
|
}
|
|
|
|
private void popClient_AuthenticationBegan(object sender, EventArgs e)
|
|
{
|
|
AddEvent("AuthenticationBegan");
|
|
}
|
|
|
|
private void popClient_AuthenticationFinished(object sender, EventArgs e)
|
|
{
|
|
AddEvent("AuthenticationFinished");
|
|
}
|
|
|
|
private void popClient_MessageTransferBegan(object sender, EventArgs e)
|
|
{
|
|
AddEvent("MessageTransferBegan");
|
|
}
|
|
|
|
private void popClient_MessageTransferFinished(object sender, EventArgs e)
|
|
{
|
|
AddEvent("MessageTransferFinished");
|
|
}
|
|
|
|
private void popClient_CommunicationLost(object sender, EventArgs e)
|
|
{
|
|
AddEvent("CommunicationLost");
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
public static void sendEmail(string server, string _port, string user, string pass, MailMessage mailMessage, Boolean enableSSL)
|
|
{
|
|
int port = 0;
|
|
bool result = Int32.TryParse(_port, out port);
|
|
if (result)
|
|
{
|
|
SmtpClient mailClient = new SmtpClient();
|
|
mailClient.Host = server;
|
|
mailClient.Port = port;
|
|
NetworkCredential cred = new NetworkCredential(user, pass);
|
|
mailClient.Credentials = cred;
|
|
mailClient.EnableSsl = enableSSL;
|
|
mailClient.Send(mailMessage);
|
|
Console.WriteLine("------Sending email on " + server + " TO: " + mailMessage.To[0].ToString() + "--------------");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Email port not numeric, error in sendEmail.");
|
|
}
|
|
}
|
|
}
|
|
}
|