///<summary>The entry point for the application.</summary> ///<param name="argv">A list of command line arguments</param> public static void Main ( String[] argv ) { Boolean booleanParseCommandLineArguments = false; string exceptionMessage = null; UtilityMailArgument utilityMailArgument = null; utilityMailArgument = new UtilityMailArgument(); booleanParseCommandLineArguments = UtilityParseCommandLineArgument.ParseCommandLineArguments ( argv, utilityMailArgument ); if ( booleanParseCommandLineArguments == false ) { // error encountered in arguments. Display usage message System.Console.Write ( UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilityMailArgument ) ) ); return; }//if ( booleanParseCommandLineArguments == false ) Stub ( ref utilityMailArgument, ref exceptionMessage ); }//static void Main( String[] argv )
}//public String UserState /// <summary>ButtonSubmit_Click().</summary> public void ButtonSubmit_Click ( Object sender, EventArgs e ) { int smtpPort = -1; String exceptionMessage = null; String smtpServer = null; String from = null; String to = null; String cc = null; String bcc = null; String subject = null; String body = null; String[] attachment = null; String userState = null; UtilityMailArgument utilityMailArgument = null; smtpPort = SmtpPort; smtpServer = SmtpServer; from = From; to = To; cc = Cc; bcc = Bcc; subject = Subject; body = Body; attachment = new String[] { Attachment }; userState = UserState; utilityMailArgument = new UtilityMailArgument ( smtpPort, smtpServer, from, to, cc, bcc, subject, body, attachment, userState ); UtilityMail.MailSend ( ref utilityMailArgument, ref exceptionMessage ); Feedback = exceptionMessage; }//public void ButtonSubmit_Click()
}//static void Main( String[] argv ) ///<summary>Stub.</summary> public static void Stub ( ref UtilityMailArgument utilityMailArgument, ref string exceptionMessage ) { MailSend ( ref utilityMailArgument, ref exceptionMessage ); //MailReceive(); }//public static void Stub()
}//public static void SendQuit ///<summary>SmtpServiceStatus</summary> public static void SmtpServiceStatus ( ref UtilityMailArgument utilityMailArgument, ref string exceptionMessage ) { int bytes = -1; //string message = null; string response = null; Byte[] data; NetworkStream networkStream = null; TcpClient tcpClient = null; try { tcpClient = new TcpClient( utilityMailArgument.smtpServer, utilityMailArgument.smtpPort ); networkStream = tcpClient.GetStream(); data = new Byte[ SizeBuffer ]; // Read the first batch of the TcpServer response bytes. bytes = networkStream.Read( data, 0, SizeBuffer ); response = Encoding.ASCII.GetString( data, 0, bytes ); if ( response.Substring(0, 3) != "220" ) { return; } System.Console.WriteLine( response ); }//try catch ( ArgumentNullException exception ) { UtilityException.ExceptionLog( exception, "ArgumentNullException", ref exceptionMessage ); } catch ( ArgumentOutOfRangeException exception ) { UtilityException.ExceptionLog( exception, "ArgumentOutOfRangeException", ref exceptionMessage ); } catch ( SocketException exception ) { UtilityException.ExceptionLog( exception, "SocketException", ref exceptionMessage ); } catch ( Exception exception ) { UtilityException.ExceptionLog( exception, "Exception", ref exceptionMessage ); } finally { if ( tcpClient != null ) { tcpClient.Close(); }//if ( tcpClient != null ) }//finally }//public static void SmtpServiceStatus()
}//public static void Stub() /* public static void MailSend ( ref String SmtpServer, ref String From, ref String To, ref String Cc, ref String Bcc, ref String Subject, ref String Body, ref String[] Attachment, ref String exceptionMessage ) { HttpContext httpContext = HttpContext.Current; MailAttachment mailAttachment = null; MailMessage = null; exceptionMessage = null; if ( string.IsNullOrEmpty( SmtpServer ) ) { SmtpServer = "localhost"; //Environment.UserDomainName; } if ( string.IsNullOrEmpty( From ) ) { From = Environment.UserName; } if ( string.IsNullOrEmpty( To ) ) { To = From; } if ( string.IsNullOrEmpty( Subject ) ) { Subject = "Subject: " + From + "@" + SmtpServer; } if ( string.IsNullOrEmpty( Body ) ) { Body = "Body: " + From + "@" + SmtpServer; } try { SmtpMail.SmtpServer = SmtpServer; = new MailMessage(); .From = From; .To = To; .Cc = Cc; .Bcc = Bcc; .Subject = Subject; .Body = Body; if ( Attachment != null ) { foreach( String AttachmentCurrent in Attachment ) { if ( AttachmentCurrent == null || AttachmentCurrent.Trim() == String.Empty ) { continue; }//if ( AttachmentCurrent == null || AttachmentCurrent.Trim() == String.Empty ) mailAttachment = new MailAttachment( AttachmentCurrent ); .Attachments.Add( mailAttachment ); }//foreach( String AttachmentCurrent in Attachment ) }//if ( Attachment != null ) SmtpMail.Send( ); }//try catch( SocketException exception ) { exceptionMessage = "SocketException: " + exception.Message; } catch( System.Web.HttpException exception ) { exceptionMessage = "HttpException: " + exception.Message; } catch ( Exception exception ) { exceptionMessage = "Exception: " + exception.Message; }//catch ( Exception exception ) if ( exceptionMessage != null ) { if ( httpContext == null ) { System.Console.WriteLine( exceptionMessage ); }//if ( httpContext == null ) else { httpContext.Response.Write( exceptionMessage ); }//else }//if ( exceptionMessage != null ) }//public static void MailSend() */ ///<summary>MailSend.</summary> public static void MailSend ( ref UtilityMailArgument utilityMailArgument, ref String exceptionMessage ) { string keyboardEntry = null; HttpContext httpContext = HttpContext.Current; MailAddress mailAddressBcc = null; MailAddress mailAddressCc = null; MailAddress mailAddressFrom = null; MailAddress mailAddressTo = null; System.Net.Mail.Attachment mailAttachment = null; System.Net.Mail.MailMessage mailMessage = null; SmtpClient smtpClient = null; exceptionMessage = null; try { smtpClient = new SmtpClient( utilityMailArgument.smtpServer ); if ( !String.IsNullOrEmpty( utilityMailArgument.bcc ) ) { mailAddressBcc = new MailAddress( utilityMailArgument.bcc ); }//if ( !String.IsNullOrEmpty( utilityMailArgument.bcc ) ) if ( !String.IsNullOrEmpty( utilityMailArgument.cc ) ) { mailAddressCc = new MailAddress( utilityMailArgument.cc ); }//if ( !String.IsNullOrEmpty( utilityMailArgument.cc ) ) mailAddressFrom = new MailAddress( utilityMailArgument.from ); mailAddressTo = new MailAddress( utilityMailArgument.to ); mailMessage = new System.Net.Mail.MailMessage ( mailAddressFrom, mailAddressTo ); if ( mailAddressBcc != null ) { mailMessage.Bcc.Add( mailAddressBcc ); }//if ( mailAddressBcc != null ) if ( mailAddressCc != null ) { mailMessage.Bcc.Add( mailAddressCc ); }//if ( mailAddressCc != null ) mailMessage.Subject = utilityMailArgument.subject; mailMessage.Body = utilityMailArgument.body; if ( utilityMailArgument.attachment != null ) { foreach( String attachment in utilityMailArgument.attachment ) { if ( !string.IsNullOrEmpty( attachment ) ) { mailAttachment = new System.Net.Mail.Attachment( attachment ); mailMessage.Attachments.Add( mailAttachment ); }//if ( !string.IsNullOrEmpty( attachment ) ) }//foreach( String attachment in utilityMailArgument.attachment ) }//if ( utilityMailArgument.attachment != null ) if ( httpContext != null ) { smtpClient.Send ( mailMessage ); }//if ( httpContext != null ) else { // Set the method that is called back when the send operation ends. smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); smtpClient.SendAsync ( mailMessage, utilityMailArgument.userState ); System.Console.WriteLine("Sending message... press c to cancel mail. Press any other key to continue."); keyboardEntry = Console.ReadLine(); // If the user canceled the send, and mail hasn't been sent yet, // then cancel the pending operation. if ( keyboardEntry.StartsWith("c") && mailSent == false ) { smtpClient.SendAsyncCancel(); }//if ( keyboardEntry.StartsWith("c") && mailSent == false ) }//if ( httpContext == null ) }//try catch( SmtpException exception ) { UtilityException.ExceptionLog( exception, "SmtpException", ref exceptionMessage ); } catch( SocketException exception ) { UtilityException.ExceptionLog( exception, "SocketException", ref exceptionMessage ); } catch( System.Web.HttpException exception ) { UtilityException.ExceptionLog( exception, "System.Web.HttpException", ref exceptionMessage ); } catch( Exception exception ) { UtilityException.ExceptionLog( exception, "Exception", ref exceptionMessage ); } finally { mailMessage.Dispose(); //smtpClient.Dispose(); } }//public static void MailSend()