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
|
private void itemenvoieLog_Click(object sender, EventArgs e)
{
_monMain.log.LogFiles("itemenvoieLog_Click()", Constant.DEBUG);
const string FileLog = "\\LogFile.log";
var _targetPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
var targetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LogDirectory");
FileSystem.Rename(targetPath + FileLog,
targetPath + "\\C2D " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.Hour + "H " +
DateTime.Now.Minute + "minutes " + DateTime.Now.Second + "secondes" + ".log");
if (
!File.Exists(
(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"Log Click2Dial " + _monMain.Macfg.AccountName + ".zip"))))
ZipFile.CreateFromDirectory(targetPath,
(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"Log Click2Dial " + _monMain.Macfg.AccountName + ".zip"))
, CompressionLevel.Optimal, false);
else
File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"Log Click2Dial " + _monMain.Macfg.AccountName + ".zip"));
string to = "Mail sender";
string from = "Mail receiver";
string subject = "Log";
string body = "Log";
MailMessage message = new MailMessage(from, to, subject, body);
var obj = new Attachment(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"Log " + _monMain.Macfg.AccountName + ".zip"), MediaTypeNames.Application.Octet);
message.Attachments.Add(obj);
try
{
SmtpClient client = new SmtpClient("serveur courrier sortant smtp", port);
client.Credentials = new NetworkCredential("AdressMail", "MDP");
client.EnableSsl = true;
client.Send(message);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
} |
Partager