system.net.mail tracing/logging without app.config file
Hi
I use System.Net.Mail to send email. I am aware I can set up comprehensive tracing/logging in the system.diagnostics part of the app.config. I would rather invoke it at run time based on user's choices. I do know one can set up tracing programmatically, but I cannot seem to get this to affect the system.net.mail thing if done this way.
(code at bottom - works for its purpose - need to )
This is in a separate class(? subroutine/file) from the main program code
Can anyone show me how to set it up to trace the system.net.sockets output? .. remember.. nothing in the app.config file.. only in this file, or the main ttstatement program
Thanks
John
using System;
using System.IO;
using System.Threading;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;
using System.Windows;
using System.Net.Mail;
namespace TTStatement
{
public class Mailer
{
private static void MailLog(string text)
{
TTStatement.TT.LogIt(text); //provided in another class
}
public static void Sendmail(string subject, string body, string To, string Bcc, string From,
string myAttachment,
string mailserver, string authlogin, string authpassword)
{
try
{
MailLog("Begin mail to: " + To + " " + subject + " ... ");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
SmtpClient SmtpServer = new SmtpClient(mailserver);
message.From = new MailAddress(From);
message.ReplyTo = new MailAddress(From);
message.To.Add(To);
message.Bcc.Add(Bcc);
message.Subject = subject;
message.Body = body;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(myAttachment);
message.Attachments.Add(attachment);
SmtpServer.Port = 26;
SmtpServer.Credentials = new System.Net.NetworkCredential(authlogin,authpassword);
SmtpServer.EnableSsl = false;
SmtpServer.Send(message);
MailLog("Sent\r\n");
}
catch (Exception ex)
{
MailLog("Failed: " + ex.ToString() + "\r\n");
}
}
}
}