473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

array for email recipients

n8kindt
221 100+
i have a function created for simple emailing (posted below). i'm new to arrays. i actually figured out how to set up the last value (Att) as an array so i could add an unlimited amount of attachments. now, i'm wondering how i could do the same for the MsgTo variable so i can add an unlimited amount of recipients. will i have to create a separate array function that will be used in the MsgTo value slot? here's my code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Function EmailMsgTo(MsgTo As String, MsgFrom As String, MsgSubject As String, _
  3. MsgBodyHTMLSite As String, MsgBodyHTMLfile As String, MsgBodyText As String, _
  4. ParamArray Att() As Variant)
  5.  
  6.  
  7. Const cdoSendUsingPickup = 1
  8. Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
  9. Const cdoAnonymous = 0
  10. Const cdoBasic = 1 ' clear text
  11. Const cdoNTLM = 2 'NTLM
  12. 'Delivery Status Notifications
  13. Const cdoDSNDefault = 0 'None
  14. Const cdoDSNNever = 1 'None
  15. Const cdoDSNFailure = 2 'Failure
  16. Const cdoDSNSuccess = 4 'Success
  17. Const cdoDSNDelay = 8 'Delay
  18. Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
  19. Dim i As Integer
  20.  
  21. Set objmsg = CreateObject("CDO.Message")
  22. Set objConf = CreateObject("CDO.Configuration")
  23.  
  24. Set objFlds = objConf.Fields
  25. With objFlds
  26.   .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  27.   'Name or IP of Remote SMTP Server
  28.   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "******************"
  29.   'Type of authentication, NONE, Basic (Base64 encoded), NTLM
  30.   .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  31.   'Your UserID on the SMTP server
  32.   .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "***************@*********"
  33.   'Your password on the SMTP server
  34.   .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "********************"
  35.   'Server port (typically 25)
  36.   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
  37.   'Use SSL for the connection (False or True)
  38.   .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  39.   'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
  40.   .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  41.   .Update
  42. End With
  43.  
  44.  
  45.  
  46.  
  47.  
  48. With objmsg
  49.   Set .Configuration = objConf
  50.   .To = MsgTo
  51.   .From = MsgFrom
  52.   .Subject = MsgSubject
  53.  
  54.   If MsgBodyHTMLSite <> "" Then
  55.   .CreateMHTMLBody MsgBodyHTMLSite
  56.   GoTo SendMsg
  57.   End If
  58.  
  59.   If MsgBodyHTMLfile <> "" Then
  60.   .htmlBody = MsgBodyHTMLfile
  61.   GoTo SendMsg
  62.   End If
  63.  
  64.   If MsgBodyText <> "" Then
  65.   .TextBody = MsgBodyText
  66.   GoTo SendMsg
  67.   End If
  68.  
  69.  
  70.  
  71.  
  72. SendMsg:
  73.       For i = LBound(Att) To UBound(Att)
  74.         objmsg.addattachment Att(i)
  75.       Next i
  76.  
  77.   .Fields("urn:schemas:mailheader:disposition-notification-to") = MsgFrom
  78.   .Fields("urn:schemas:mailheader:return-receipt-to") = MsgFrom
  79.   .DSNOptions = cdoDSNSuccessFailOrDelay
  80.   .Fields.Update
  81.   .Send
  82. End With
  83. End Function
Jun 16 '08 #1
8 5982
Dököll
2,364 Expert 2GB
Hello, n8kindt!

I don't like arrays either, but do stay tuned for a better answer, I am not telling you what you need here.

Are you trying to set up a mass email program? You could probably figure out code to simply add separators after each email address rather than an array of fields, if you're interested; just a shortcut since I absolutely dislike arrays:-)

Good luck!

Dököll
Jun 17 '08 #2
n8kindt
221 100+
Hello, n8kindt!

I don't like arrays either, but do stay tuned for a better answer, I am not telling you what you need here.

Are you trying to set up a mass email program? You could probably figure out code to simply add separators after each email address rather than an array of fields, if you're interested; just a shortcut since I absolutely dislike arrays:-)

Good luck!

Dököll
thanks for your reply! it's not really a mass email program per se. i suppose you could call it that. but yeah i would be interested in that code! how would i go about doing that?

i have actually already set up a program that emails personal reports before. but that uses a loop and only does one email at a time. now i'm just trying to set up a simple email program that allows users to send messages to multiple recipients (just like you would if u were in gmail, yahoo, etc, etc where u check each recipient and it jams all those addresses in the "to" field) all at once instead of one at a time.

i actually haven't figured out an efficient way of selecting the recipients either. but i'm working on it.
Jun 17 '08 #3
ADezii
8,834 Expert 8TB
I'm not exactly sure that I fully understand your request, but perhaps you can use a common Delimiter between Recipients, use the Split() Function to populate a Variant Array with the items, then it would be an easy matter to iterate through them, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strRecipients As String
  2. Dim varRecipients As Variant
  3. Dim intCounter As Integer
  4.  
  5. strRecipients = "Tom;Fred;Gil;Jane;Holly;Matt"
  6.  
  7. varRecipients = Split(strRecipients, ";")
  8.  
  9. For intCounter = LBound(varRecipients) To UBound(varRecipients)
  10.   Debug.Print varRecipients(intCounter)
  11. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Tom
  2. Fred
  3. Gil
  4. Jane
  5. Holly
  6. Matt
Is this what you are looking for?
Jun 17 '08 #4
n8kindt
221 100+
I'm not exactly sure that I fully understand your request, but perhaps you can use a common Delimiter between Recipients, use the Split() Function to populate a Variant Array with the items, then it would be an easy matter to iterate through them, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strRecipients As String
  2. Dim varRecipients As Variant
  3. Dim intCounter As Integer
  4.  
  5. strRecipients = "Tom;Fred;Gil;Jane;Holly;Matt"
  6.  
  7. varRecipients = Split(strRecipients, ";")
  8.  
  9. For intCounter = LBound(varRecipients) To UBound(varRecipients)
  10.   Debug.Print varRecipients(intCounter)
  11. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Tom
  2. Fred
  3. Gil
  4. Jane
  5. Holly
  6. Matt
Is this what you are looking for?
ok, at first i didn't see what u were getting at but now i do. hmmm this is probably the best idea thus far. and it should do the trick.

now i get to work on figuring out how to add recipients thru interface. i'd like to use a checkbox interface (if the recipients are checked and then the ok button pressed, they are jammed into this array) like most web email programs use but i'm open to anything at this point. if anyone has any bright ideas, i would appreciate it if they shared their knowledge..

and thanks, ADezii! very much appreciated your reply!
Jun 17 '08 #5
ADezii
8,834 Expert 8TB
ok, at first i didn't see what u were getting at but now i do. hmmm this is probably the best idea thus far. and it should do the trick.

now i get to work on figuring out how to add recipients thru interface. i'd like to use a checkbox interface (if the recipients are checked and then the ok button pressed, they are jammed into this array) like most web email programs use but i'm open to anything at this point. if anyone has any bright ideas, i would appreciate it if they shared their knowledge..

and thanks, ADezii! very much appreciated your reply!
Let's assume you have a Data Source with a [Recipient] (Yes/No Field) and a [Name] Field, and that this Data Source is named tblTest. The following code will store into an Array the Names of all Recipients ([Recipient] = Yes/True and Name Not Null). It would then be a simple matter to retrieve them. Any questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim intNumOfRecipients As Integer
  4. Dim intIndex As Integer
  5. Dim intCounter As Integer
  6.  
  7. intArrayIndex = 1       'initialize
  8.  
  9. '# of Recipients ([Recipient] = Yes/True
  10. intNumOfRecipients = DCount("*", "tblTest", "[Recipient] = True")
  11.  
  12. Set MyDB = CurrentDb()
  13. Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
  14.  
  15. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  16.  ReDim astrRecipients(1 To intNumOfRecipients) As String
  17.   With MyRS
  18.     Do While Not .EOF
  19.       'If [Recipient] is checked and a valid Name
  20.       If ![Recipient] And Not IsNull(![Name]) Then
  21.         astrRecipients(intArrayIndex) = ![Name]     'add to Array
  22.         intArrayIndex = intArrayIndex + 1           'increment Index
  23.       End If
  24.       .MoveNext
  25.     Loop
  26. End With
  27. End If
  28.  
  29. MyRS.Close
  30. Set MyRS = Nothing
  31.  
  32. 'Playback time
  33. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  34.   For intCounter = LBound(astrRecipients) To UBound(astrRecipients)
  35.     Debug.Print astrRecipients(intCounter)
  36.   Next
  37. End If
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Helen
  2. Regina
  3. Peggy
  4. Vince
  5. Joe
  6. Tom
  7. Mary
Jun 17 '08 #6
n8kindt
221 100+
Let's assume you have a Data Source with a [Recipient] (Yes/No Field) and a [Name] Field, and that this Data Source is named tblTest. The following code will store into an Array the Names of all Recipients ([Recipient] = Yes/True and Name Not Null). It would then be a simple matter to retrieve them. Any questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim intNumOfRecipients As Integer
  4. Dim intIndex As Integer
  5. Dim intCounter As Integer
  6.  
  7. intArrayIndex = 1       'initialize
  8.  
  9. '# of Recipients ([Recipient] = Yes/True
  10. intNumOfRecipients = DCount("*", "tblTest", "[Recipient] = True")
  11.  
  12. Set MyDB = CurrentDb()
  13. Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
  14.  
  15. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  16.  ReDim astrRecipients(1 To intNumOfRecipients) As String
  17.   With MyRS
  18.     Do While Not .EOF
  19.       'If [Recipient] is checked and a valid Name
  20.       If ![Recipient] And Not IsNull(![Name]) Then
  21.         astrRecipients(intArrayIndex) = ![Name]     'add to Array
  22.         intArrayIndex = intArrayIndex + 1           'increment Index
  23.       End If
  24.       .MoveNext
  25.     Loop
  26. End With
  27. End If
  28.  
  29. MyRS.Close
  30. Set MyRS = Nothing
  31.  
  32. 'Playback time
  33. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  34.   For intCounter = LBound(astrRecipients) To UBound(astrRecipients)
  35.     Debug.Print astrRecipients(intCounter)
  36.   Next
  37. End If
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Helen
  2. Regina
  3. Peggy
  4. Vince
  5. Joe
  6. Tom
  7. Mary
wow, i am so glad you saved me the headache of trying to set up that array! i think i've learned more about arrays from this code than i have researching them the last two days! thank you so much. i think i can take care of the rest myself from here.

cheers,
nate
Jun 17 '08 #7
ADezii
8,834 Expert 8TB
wow, i am so glad you saved me the headache of trying to set up that array! i think i've learned more about arrays from this code than i have researching them the last two days! thank you so much. i think i can take care of the rest myself from here.

cheers,
nate
You are quite welcome Nate, good luck and keep in touch,
Jun 17 '08 #8
n8kindt
221 100+
You are quite welcome Nate, good luck and keep in touch,
turns out, that i didn't actually need an array to add multiple recipients. the .to is populated by a giant string that separates the email recipients by using delimiter ";" AFTER it is sent thru my code... i still needed an array to pile all the recipients into one string though. here we go...



i have a email form that can be populated by clicking on managers, supervisors, or all buttons. i'll use managers for this demo. the manager click event opens the manager list whose load form event goes like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.     Set DB = CurrentDb
  4.     Set qdf = DB.QueryDefs("qryEmailListManagers")
  5.     Set RS = qdf.OpenRecordset()
  6. With RS
  7. If Not .EOF Then
  8. .MoveFirst
  9. Do
  10. .Edit
  11. .Fields!CheckBox = True
  12. .Update
  13. .MoveNext
  14. Loop Until .EOF
  15. End If
  16. .Close
  17. End With
  18. DB.Close
  19. Set RS = Nothing
  20. Set DB = Nothing
  21. qdf.Close
  22. Set qdf = Nothing
  23.  
  24.  
  25. End Sub



once the user picks the appropriate records, they click the ok button and the onclick fires this event and throws the string into the to field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. Dim DB As DAO.Database
  3. Dim RS As DAO.Recordset
  4. Dim qdf As DAO.QueryDef
  5. Dim intNumOfRecipients As Integer
  6. Dim intIndex As Integer
  7. Dim intCounter As Integer
  8. Dim FName As String
  9. Dim FQName As String
  10. Dim EmailA As String
  11. Dim strMsgTo As String
  12. Dim strTo As String
  13.  
  14. intArrayIndex = 1       'initialize
  15.  
  16. '# of Recipients ([Recipient] = Yes/True
  17. intNumOfRecipients = DCount("*", "QryEmailListManagers", "[CheckBox] = True")
  18. strTo = ""
  19.  
  20.  
  21. Set DB = CurrentDb
  22. Set qdf = DB.QueryDefs("qryEmailListManagers")
  23. Set RS = qdf.OpenRecordset()
  24.  
  25.  
  26. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  27.  ReDim astrRecipients(1 To intNumOfRecipients) As String
  28.   With RS
  29.     Do While Not .EOF
  30.       'If [Recipient] is checked and a valid Name
  31.       If ![CheckBox] = True And Not IsNull(![email]) Then
  32.         FName = ![First Name]
  33.         FQName = """" & FName & """"
  34.         EmailA = !Email
  35.         strMsgTo = FQName & " <" & EmailA & ">" & "; "
  36.  
  37.         strTo = strTo & strMsgTo
  38.       End If
  39.       .MoveNext
  40.     Loop
  41. End With
  42. End If
  43.  
  44. RS.Close
  45. Set MyRS = Nothing
  46.  
  47. Forms!frmEmailForm.txtTo.Value = strTo
  48. Debug.Print strTo
  49. If intNumOfRecipients > 0 Then      'need at least 1 Recipient
  50.   For intCounter = LBound(astrRecipients) To UBound(astrRecipients)
  51.     Debug.Print astrRecipients(intCounter)
  52.   Next
  53. End If
  54.  



and that is pretty much it. it wasn't easy as it looks for me b/c i have some tricky variables to work around that were particular only to my situation. i have a email function (posted above) that grabs all the info from the form and emails it out. right now, my next task is to create a way for a user to select their attachment file by clicking on the "browse" button. right now you have to copy and paste the entire file name. any ideas? i'm also going to post another thread for that specific topic

props again to ADezii... i would have cracked my head in two trying to figure out how to do that array without him since i didn't have any real background in them before.
Jun 20 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nigi | last post by:
I've made a mysql database with php front end which, in part, contains mailing lists. I've used a mailto: link to create a new email with their names in the bcc: field. Unfortunatley their is a...
1
by: Nicole | last post by:
Hello! I hope there is someone out there who can shed some light on this for me. I have a module that is supposed to look at an access table, pull out each bid record, link to another table to...
2
by: .Net Newbie | last post by:
Hello, I am currently coding my ASP.Net pages in c# and have run into a question concerning Emails. I have four objects on a page (six including 2 buttons). The first is a subject line...
8
by: Jimbo | last post by:
Hello I am currently designing an internal ordering system for IT equipment. I am designing it in ASP.NET (vb) using Visual Studio 2003 and using Microsoft SQL Server I have got the system...
0
by: gillespie.amanda | last post by:
How do I add a Sender name to the emails sent by the following script: def createhtmlmail (html, text, subject): """Create a mime-message that will render HTML in popular MUAs, text in better...
1
by: handokowidjaja | last post by:
Hi All, Several weeks ago i started a topic with the same subject, however the solutions provided was for using MS Outlook (fullblown version). I finally found something that works directly with...
1
by: darklink64 | last post by:
Hi, I've recently set up a database, but have not experience of VBA and need to find a way of solving this problem. Basically, I would like to make a form with two buttons. On clicking one...
11
by: MLH | last post by:
The following procedures found at http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm are meant to work together in harmony to effect eMail sends via OE. The last procedure (FN SplitB)...
2
by: kennykenn | last post by:
Hi, Ive producd code to send an email after capturing info off a form,it works fine locally but when i put it live it doesnt work! the code is stopin at 'msg.send' any ideas, here the code! ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.