''' <summary>
''' A class to send eMails. There are plenty of overloads available to serv your need.
''' </summary>
''' <remarks><see cref="eMail.QuickSend" /> will send one email with the specified recepients while <see cref="email.BulkSend" /> will send email to each recepient individually.</remarks>
Public Class eMail

    ''' <summary>
    ''' <para>Source: <a href="http://www.regular-expressions.info/email.html">http://www.regular-expressions.info/email.html</a></para>
    ''' <para>For list of Generic Top Level Domain (TLD) names go to <a href="http://www.iana.org/gtld/gtld.htm">http://www.iana.org/gtld/gtld.htm</a></para>
    ''' <para>There is only one problem with this reguler expression is that it will allow any two character as a valid TLD.</para>
    ''' <para>Valid list of two character TLD for counties go to <a href="http://www.iana.org/root-whois/index.html">http://www.iana.org/root-whois/index.html</a></para>
    ''' <para>Other good reference for TLD:
    ''' <list type="bullet">
    ''' <item><a href="http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains">http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains</a>
    ''' </item>
    ''' <item><a href="http://wiki.mozilla.org/TLD_List">http://wiki.mozilla.org/TLD_List</a>
    ''' </item>
    ''' </list>
    ''' </para>
    ''' <para>
    ''' I found a good regular expression for email verfication at above site. I modified a bit to be little better. This expression not only verifies the email address but also groups the email id (part before @) and server name (part after @) in it.
    ''' </para>
    ''' <para>Thing to remmeber: This expression will only accept lower case. If you want to have case insensitive match then either use flags when you use it or use the <see cref="rgxEmail2" /></para>
    ''' </summary>
    Public Const rgxEmail As String = "^([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*)@((?:(?:[a-z0-9]+?\.)+(?:aero|asia|biz|cat|com|coop|info|jobs|mobi|museum|name|net|org|pro|tel|travel|gov|edu|mil|int|[a-z]{2}))|(?:[[](?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})[]]))$"

    ' Here is simplified version to use in .NET programs. The belove exp. will work and ignore case in both .NET and JavaScript.
    ' The following is similar as above but will not work in JavaScript.
    ' Why this works in .NET and not in JavaScript?
    ' Answer: It's not the fault of JavaScript. JavaScript has diferant way to say to ignore case but the scripts generated by 
    '         .NET doenot put any flags for it nor there is any properties to set the flag.

    ' In reg exp. belove is has the 'com' TLD is written this way (?:(?:c|C)(?:o|O)(?:m|M))
    ' So use that as an example if you want to add any new TLD
    ''' <summary>
    ''' This is same as <see cref="rgxEmail" /> except that this does not need any flag to ingnore case. It is written to accept either case. 
    ''' </summary>
    Public Const rgxEmail2 As String = "^([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*)@((?:[a-zA-Z0-9]+?\.)+(?:(?:(?:a|A)(?:e|E)(?:r|R)(?:o|O))|(?:(?:a|A)(?:s|S)(?:i|I)(?:a|A))|(?:(?:b|B)(?:i|I)(?:z|Z))|(?:(?:c|C)(?:a|A)(?:t|T))|(?:(?:c|C)(?:o|O)(?:m|M))|(?:(?:c|C)(?:o|O)(?:o|O)(?:p|P))|(?:(?:i|I)(?:n|N)(?:f|F)(?:o|O))|(?:(?:j|J)(?:o|O)(?:b|B)(?:s|S))|(?:(?:m|M)(?:o|O)(?:b|B)(?:i|I))|(?:(?:m|M)(?:u|U)(?:s|S)(?:e|E)(?:u|U)(?:m|M))|(?:(?:n|N)(?:a|A)(?:m|M)(?:e|E))|(?:(?:n|N)(?:e|E)(?:t|T))|(?:(?:o|O)(?:r|R)(?:g|G))|(?:(?:p|P)(?:r|R)(?:o|O))|(?:(?:t|T)(?:e|E)(?:l|L))|(?:(?:t|T)(?:r|R)(?:a|A)(?:v|V)(?:e|E)(?:l|L))|(?:(?:g|G)(?:o|O)(?:v|V))|(?:(?:e|E)(?:d|D)(?:u|U))|(?:(?:m|M)(?:i|I)(?:l|L))|(?:(?:i|I)(?:n|N)(?:t|T))|[a-zA-Z]{2})|(?:[[](?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})[]]))$"

    ''' <summary>
    ''' To match an IP (IPv4) address.
    ''' </summary>
    Public Const rexIPv4 As String = "((?:(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2}?))"

#Region "QuickSend"

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, Nothing, Nothing, False, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, False, Nothing)
    End Sub

    '''' <summary>
    '''' Send an quick email.
    '''' </summary>
    '''' <param name="p_smtp_server">The smtp server name/address.</param>
    '''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    '''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    '''' <param name="p_subject">The subject line.</param>
    '''' <param name="p_body">The message of the email.</param>
    '''' <param name="p_attachments">The attachments.</param>
    'Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
    '        ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
    '        ByVal ParamArray p_attachments() As String)

    '    QuickSend(p_smtp_server, p_to, p_from, p_subject, p_body, Nothing, Nothing, False, _
    '        System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, False, p_attachments)
    'End Sub

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, False, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, False, p_attachments)
    End Sub

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, False, p_attachments)
    End Sub

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, Nothing, Nothing, -1, False, False, p_attachments)
    End Sub

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_smtp_user">The smtp user id for authentication.</param>
    ''' <param name="p_smtp_password">The smtp password for authentication.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal p_smtp_user As String, _
            ByVal p_smtp_password As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, p_smtp_user, p_smtp_password, -1, False, False, p_attachments)
    End Sub

    ''' <summary>
    ''' Send an quick email.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_smtp_user">The smtp user id for authentication.</param>
    ''' <param name="p_smtp_password">The smtp password for authentication.</param>
    ''' <param name="p_port">The smtp server port.</param>
    ''' <param name="p_ssl">if set to <c>true</c> if you want to use SSL.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub QuickSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal p_smtp_user As String, _
            ByVal p_smtp_password As String, ByVal p_port As Integer, _
            ByVal p_ssl As Boolean, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, p_smtp_user, p_smtp_password, -1, False, False, p_attachments)
    End Sub

#End Region

#Region "BulkSend"

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, Nothing, Nothing, False, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, True, Nothing)
    End Sub

    '''' <summary>
    '''' Send one email per recepient.
    '''' </summary>
    '''' <param name="p_smtp_server">The smtp server name/address.</param>
    '''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    '''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    '''' <param name="p_subject">The subject line.</param>
    '''' <param name="p_body">The message of the email.</param>
    '''' <param name="p_attachments">The attachments.</param>
    'Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
    '        ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
    '        ByVal ParamArray p_attachments() As String)

    '    QuickSend(p_smtp_server, p_to, p_from, p_subject, p_body, Nothing, Nothing, False, _
    '        System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, True, p_attachments)
    'End Sub

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, False, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, True, p_attachments)
    End Sub

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            System.Text.Encoding.Default, Net.Mail.MailPriority.Normal, Nothing, Nothing, Nothing, -1, False, True, p_attachments)
    End Sub

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, Nothing, Nothing, -1, False, True, p_attachments)
    End Sub

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_smtp_user">The smtp user id for authentication.</param>
    ''' <param name="p_smtp_password">The smtp password for authentication.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
                ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
                ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
                ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
                ByVal p_reply_to As String, ByVal p_smtp_user As String, _
                ByVal p_smtp_password As String, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, p_smtp_user, p_smtp_password, -1, False, True, p_attachments)
    End Sub

    ''' <summary>
    ''' Send one email per recepient.
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_smtp_user">The smtp user id for authentication.</param>
    ''' <param name="p_smtp_password">The smtp password for authentication.</param>
    ''' <param name="p_port">The smtp server port.</param>
    ''' <param name="p_ssl">if set to <c>true</c> if you want to use SSL.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub BulkSend(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal p_smtp_user As String, _
            ByVal p_smtp_password As String, ByVal p_port As Integer, _
            ByVal p_ssl As Boolean, ByVal ParamArray p_attachments() As String)

        Send(p_smtp_server, p_to, p_from, p_subject, p_body, p_cc, p_bcc, p_html_body, _
            p_encoding, p_priority, p_reply_to, p_smtp_user, p_smtp_password, -1, False, False, p_attachments)
    End Sub

#End Region

    ''' <summary>
    ''' Send email(s).
    ''' </summary>
    ''' <param name="p_smtp_server">The smtp server name/address.</param>
    ''' <param name="p_to">The list of recepients. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_from">The senders email address. Display name seperated by |.</param>
    ''' <param name="p_subject">The subject line.</param>
    ''' <param name="p_body">The message of the email.</param>
    ''' <param name="p_cc">The list of recepients to put in CC list. Multiple email seperated by ';'. Display name seperated by '|'.</param>
    ''' <param name="p_bcc">The list of recepients to put in Bcc list.</param>
    ''' <param name="p_html_body"><c>true</c> if email message is in HTML format; otherwise <c>false</c>.</param>
    ''' <param name="p_encoding">The encoding to use in body and subject line.</param>
    ''' <param name="p_priority">The priority of the email.</param>
    ''' <param name="p_reply_to">The reply to email address.</param>
    ''' <param name="p_smtp_user">The smtp user id for authentication.</param>
    ''' <param name="p_smtp_password">The smtp password for authentication.</param>
    ''' <param name="p_port">The smtp server port.</param>
    ''' <param name="p_ssl">if set to <c>true</c> if you want to use SSL.</param>
    ''' <param name="p_bulk">if set to <c>true</c> if you want to send one email per recepient.</param>
    ''' <param name="p_attachments">The attachments.</param>
    Public Shared Sub Send(ByVal p_smtp_server As String, ByVal p_to As String, _
            ByVal p_from As String, ByVal p_subject As String, ByVal p_body As String, _
            ByVal p_cc As String, ByVal p_bcc As String, ByVal p_html_body As Boolean, _
            ByVal p_encoding As System.Text.Encoding, ByVal p_priority As System.Net.Mail.MailPriority, _
            ByVal p_reply_to As String, ByVal p_smtp_user As String, _
            ByVal p_smtp_password As String, ByVal p_port As Integer, _
            ByVal p_ssl As Boolean, ByVal p_bulk As Boolean, ByVal ParamArray p_attachments() As String)

        Dim l_mail As System.Net.Mail.MailMessage
        Dim l_emails(), l_email As String
        Dim l_address As System.Net.Mail.MailAddress
        Dim smtp As New System.Net.Mail.SmtpClient(p_smtp_server)

        If p_bulk Then
            If Not String.IsNullOrEmpty(p_cc) Then p_to &= ";" & p_cc
            p_cc = Nothing
            If Not String.IsNullOrEmpty(p_bcc) Then p_to &= ";" & p_bcc
            p_bcc = Nothing
        End If

        l_mail = New System.Net.Mail.MailMessage()
        With l_mail
            If Not String.IsNullOrEmpty(p_from) Then
                .From = mail_address(p_from)
                .Sender = mail_address(p_from)
            End If
            If Not String.IsNullOrEmpty(p_cc) Then
                l_emails = p_cc.Split(";"c)
                For Each l_email In l_emails
                    l_address = mail_address(l_email)
                    If l_address IsNot Nothing Then
                        .CC.Add(l_address)
                    End If
                Next
            End If
            If Not String.IsNullOrEmpty(p_bcc) Then
                l_emails = p_bcc.Split(";"c)
                For Each l_email In l_emails
                    l_address = mail_address(l_email)
                    If l_address IsNot Nothing Then
                        .Bcc.Add(l_address)
                    End If
                Next
            End If
            .Subject = p_subject
            .Body = p_body
            .IsBodyHtml = p_html_body
            .BodyEncoding = p_encoding
            .SubjectEncoding = p_encoding
            .Priority = p_priority
            If p_reply_to IsNot Nothing Then .ReplyTo = mail_address(p_reply_to)
            If p_attachments IsNot Nothing AndAlso p_attachments.Length > 0 Then
                For Each l_email In p_attachments
                    If System.IO.File.Exists(l_email) Then
                        .Attachments.Add(New System.Net.Mail.Attachment(l_email))
                    End If
                Next
            End If
        End With

        If Not (String.IsNullOrEmpty(p_smtp_user) OrElse p_smtp_user.Trim.Length = 0) Then
            smtp.UseDefaultCredentials = False
            smtp.Credentials = New System.Net.NetworkCredential(p_smtp_user, p_smtp_password)
        End If
        If p_port > 0 Then smtp.Port = p_port
        smtp.EnableSsl = p_ssl

        If p_bulk Then
            l_emails = p_to.Split(";"c)
            For Each l_email In l_emails
                l_address = mail_address(l_email.Trim)
                If l_address IsNot Nothing Then
                    l_mail.To.Clear()
                    If String.IsNullOrEmpty(p_from) Then
                        l_mail.From = mail_address(l_email.Trim)
                        l_mail.Sender = mail_address(l_email.Trim)
                    End If
                    l_mail.To.Add(l_address)
                    smtp.Send(l_mail)
                End If
            Next
        Else
            l_emails = p_to.Split(";"c)
            For Each l_email In l_emails
                l_address = mail_address(l_email)
                If l_address IsNot Nothing Then
                    l_mail.To.Add(l_address)
                End If
            Next
            If String.IsNullOrEmpty(p_from) Then
                If l_mail.To.Count > 0 Then
                    p_from = l_mail.To(0).Address
                ElseIf l_mail.CC.Count > 0 Then
                    p_from = l_mail.CC(0).Address
                ElseIf l_mail.Bcc.Count > 0 Then
                    p_from = l_mail.Bcc(0).Address
                End If
                l_mail.From = mail_address(p_from)
                l_mail.Sender = mail_address(p_from)
            End If
            If l_mail.To.Count > 0 Then
                smtp.Send(l_mail)
            Else
                Throw New Exception("No recepient specified.")
            End If
        End If
    End Sub

    Private Shared Function mail_address(ByVal p_address As String) As System.Net.Mail.MailAddress
        Dim l_address As System.Net.Mail.MailAddress
        Dim l_parts() As String
        Dim l_name, l_email As String
        Dim l_rgx As System.Text.RegularExpressions.Match

        l_address = Nothing
        If String.IsNullOrEmpty(p_address) Then Return Nothing
        l_parts = p_address.Split("|"c)
        If l_parts.Length = 2 Then
            l_name = l_parts(0).Trim
            l_email = l_parts(1).Trim
            l_rgx = System.Text.RegularExpressions.Regex.Match(l_email, rgxEmail)
            If l_rgx.Success Then
                l_address = New System.Net.Mail.MailAddress(l_email, l_name)
            Else
                l_rgx = System.Text.RegularExpressions.Regex.Match(l_name, rgxEmail)
                If l_rgx.Success Then
                    l_address = New System.Net.Mail.MailAddress(l_name, l_email)
                End If
            End If
        ElseIf l_parts.Length > 0 Then
            l_email = l_parts(0).Trim
            l_rgx = System.Text.RegularExpressions.Regex.Match(l_email, rgxEmail)
            If l_rgx.Success Then l_address = New System.Net.Mail.MailAddress(l_email)
        End If

        Return l_address
    End Function
End Class
