I am working on an inventory ordering system where I send a different number of email addresses depending on the vendor. I am trying to use one sub to do this instead of the 8 subs it would take if I created one for each vendor.
I have 1 sub that requires 6 Send addresses, 3 that require 4 Send Addresses and 4 that require 4 Send Addresses. Is it possible to this all with one sub leaving blanks in the arguments so that they are ignored?
Code:Private Sub FireEMail() ' The first email has 6 addresses MightyEmail( _ "[email protected]", _ "[email protected]", _ "[email protected]", _ "[email protected]", _ "[email protected]", _ "[email protected]", _ "[email protected]", _ "strSubject", "strBody", "strPath") ' The second email has 4 addresses MightyEmail( _ "[email protected]", _ "strTo1Somewhereelse.com", _ "StrTo2Somewhereelse.com", _ "StrTo3Somewhereelse.com", _ "strSubject", "strBody", "strPath") ' The fourth has 4 etc.. End Sub Private Sub MightyEmail( _ ByVal StrMailFrom As String, _ ByVal strMailTo1 As String, _ ByVal strMailTo2 As String, _ ByVal strMailTo3 As String, _ ByVal strMailTo4 As String, _ ByVal strMailTo5 As String, _ ByVal strmailTo6 As String, _ ByVal StrSubject As String, _ ByVal StrBody As String, _ ByVal strFPath As String) Dim message As New MailMessage message.From = New MailAddress(StrMailFrom) message.To.Add(strMailTo1) message.To.Add(strMailTo2) message.To.Add(strMailTo3) message.To.Add(strMailTo4) message.To.Add(strMailTo5) message.To.Add(strmailTo6) message.Subject = StrSubject message.Body = StrBody Dim emailClient As New SmtpClient(strMailServer) emailClient.Credentials = (SMTP_Cred) emailClient.DeliveryMethod = SmtpDeliveryMethod.Network emailClient.EnableSsl = True Try emailClient.Send(message) MessageBox.Show("done") Catch ex As Exception MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace) Finally End Try End Sub




Reply With Quote