Create GroupWise Email with Access

crhodus

Registered User.
Local time
Today, 13:59
Joined
Mar 16, 2001
Messages
257
I'm using the following code that I found to create an email with GroupWise 6.5. I modified a few thing so it's a little different from the original I was wonder how I can send the message to multiple recipients when adding 2 or more email addresses in the txtTo textbox on my form.

I thought that the following code might send the message to another person( strRecTo(1, 0) = "jdoe@12345.com") but it did not work. Also I tried entering the email address like this in txtTo field, but it did not work either. (johndoe@12345.com;janedoe@12345.com).

Can anyone tell if there something that I need to change or add? The code uses a module named GW that I imported into the database.

Thanks!


Private Sub btnCreateEmail_Click()
On Error GoTo Err_Handler
Dim strTemp As String
''Dim varAttach(1) As Variant
Dim strRecTo(1, 0) As String
Dim lngCount As Long
Dim varProxies As Variant
Dim cGW As GW
Dim ErrorMessage As String
ErrorMessage = ""

''varAttach(0) = "c:\command.com"
''varAttach(1) = "c:\windows\readme.txt"
If IsNull(Me.txtTo) = False Then
strRecTo(0, 0) = Me.txtTo
strRecTo(1, 0) = "jdoe@12345.com"
Else
ErrorMessage = ErrorMessage & " There is no TO: address listed."
End If

Set cGW = New GW
With cGW
.Login
.RecTo = strRecTo
.Priority = "Medium"
' .FileAttachments = varAttach
' .FromText = Me.txtFrom
If IsNull(Me.txtBody) = False Then .BodyText = Me.txtBody
If IsNull(Me.txtSubject) = False Then .Subject = Me.txtSubject
If IsNull(Me.txtBc) = False Then .RecBc = Me.txtBc
If IsNull(Me.txtCC) = False Then .RecCc = Me.txtCC
strTemp = .CreateMessage
.ResolveRecipients strTemp
If IsArray(.NonResolved) Then MsgBox "Some unresolved recipients." & ErrorMessage
.SendMessage strTemp
.DeleteMessage strTemp, True
End With

Exit_Here:
Set cGW = Nothing
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
Resume Exit_Here

End Sub
 
OK, disclaimer, the last version of Groupwise I used was 4.5, we switched to exchange after that. But If I recall correctly (I can't find any "old" code to confirm this) there is a method of the GW object that allows you to ADD a sendto address. Think of it like a list or combobox that uses an ADDITEM. If I recall it was an indexed property you had to handle with the index. This may have changed since that version, or maybe I recall incorrectly (been 4 years) but maybe it will help. I hope I am not misleading you on this.
 
Thanks for your help FoFa. I couldn't fine any type of Add property, but I did figure out that if I add another .RecTo for each additional email address, the message will be sent out to multiple addresses.

crhodus
 
Groupwise email

Were you ever able to solve this? I'm looking for anyone that has been able to successfully send an email to groupwise from an access form.

Thanks
 
sdelgado said:
Were you ever able to solve this? I'm looking for anyone that has been able to successfully send an email to groupwise from an access form.

Thanks

Done and done;

Code:
Function Groupwise_Mail(ByRef myRecipients() As String, ByRef myAttachments() As String, ByVal mySubject As String, ByVal myBodytext As String)
    ' Declare the objects
    Dim objGroupWise As Object
    Dim objAccount As Object
    Dim objMessages As Object
    Dim objMessage As Object
    Dim objMailBox As Object
    Dim objRecipients As Object
    Dim objRecipient As Object
    Dim Recipient As Variant
    Dim objAttachment As Object
    Dim objAttachments As Object
    Dim Attachment As Variant
    Dim objMessageSent As Variant

    On Error GoTo Errorhandling

    ' Now build the GroupWise message object
    Set objGroupWise = CreateObject("NovellGroupWareSession")
    Set objAccount = objGroupWise.Login
    Set objMailBox = objAccount.MailBox
    Set objMessages = objMailBox.Messages
    Set objMessage = objMessages.Add("GW.MESSAGE.MAIL", "Draft")

    ' Add each of the Recipients
    Set objRecipients = objMessage.Recipients
    For Each Recipient In myRecipients
        Set objRecipient = objRecipients.Add(Recipient)
    Next Recipient

    ' Add each of the attachments
    Set objAttachments = objMessage.Attachments
    For Each Attachment In myAttachments
        Set objAttachment = objAttachments.Add(Attachment)
    Next Attachment

    ' Add the Subject/Body Text
    With objMessage
        .Subject = mySubject
        .Bodytext = myBodytext
    End With

    ' Send it
    Set objMessageSent = objMessage.Send

    ExitHere:
    Set objGroupWise = Nothing
    Set objAccount = Nothing
    Set objMailBox = Nothing
    Set objMessages = Nothing
    Set objMessage = Nothing
    Set objRecipients = Nothing
    Set objAttachments = Nothing
    Set objRecipient = Nothing
    Set objAttachment = Nothing
    Exit Function

    Errorhandling:
    MsgBox Err.DESCRIPTION & " " & Err.Number
    Resume ExitHere

End Function

and an example sub;

Code:
Sub TestEmailFunc()
    ReDim TestEmails(1) As String

    TestEmails(1) = "bill.gates@homtail.com"

    ReDim TestAttachments(1) As String

    TestAttachments(1) = "C:\config.sys"

    Dim TestSubject As String
    TestSubject = "Test Email Function"

    Dim TestBody As String
    TestBody = "Hey, its all working now baby!"

    Call Groupwise_Mail(TestEmails(), TestAttachments(), TestSubject, TestBody)

End Sub
 
How would I be able to change the GW account that it logs into to send the email.

What line of code do I need to add or modify to have this done.
I want to specify the userID, Address, and port number.. is this possible?

Thanks,
 
I liked the code you have, but when I run it it gives me the error: an invalid argument was passed in the function call. What am I doing wrong?
Thanks.:confused:
 
I liked the code you have, but when I run it it gives me the error: an invalid argument was passed in the function call. What am I doing wrong?
Thanks.:confused:
Try replacing the line:
Call Groupwise_Mail(TestEmails(), TestAttachments(), TestSubject, TestBody)

with this line:
Call Groupwise_Mail(TestEmails, TestAttachments, TestSubject, TestBody)

You only need the name of the array to be passed to the function. This worked for me!
 
Hi use this piece of code and this works fine, only thing that is needed is to save the attachement in a predetermined place:

Bob

Code:
Sub MailToGroup()
Call SendNotesMail("Test", "C:\Test.txt", "[EMAIL="myaddress@mailaddress.com"]myaddress@mailaddress.com[/EMAIL]", "Hi testing", True)
End Sub
 
Public Sub SendNotesMail(Subject As String, attachment As String, recipient As String, bodytext As String, saveit As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'For Multiple Email Addresses
Dim recip(25) As Variant
 
'Set up additional E-mail addresses
recip(0) = "[EMAIL="myaddress@mailaddress.com"][COLOR=#0000ff]myaddress@mailaddress.com[/COLOR][/EMAIL]"
recip(1) = "[EMAIL="myaddress1@mailaddress.com"][COLOR=#0000ff]myaddress1@mailaddress.com[/COLOR][/EMAIL]"
recip(2) = "[EMAIL="myaddress2@mailaddress.com"][COLOR=#0000ff]myaddress2@mailaddress.com[/COLOR][/EMAIL]"
recip(3) = "[EMAIL="myaddress3@mailaddress.com"][COLOR=#0000ff]myaddress3@mailaddress.com[/COLOR][/EMAIL]"
recip(4) = "[EMAIL="myaddress4@mailaddress.com"][COLOR=#0000ff]myaddress4@mailaddress.com[/COLOR][/EMAIL]"
recip(5) =  etc..........
 
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
Do Until Maildb.IsOpen
'If Maildb.ISOPEN = True Then
'     'Already open for mail
'Else
'MsgBox "This program will send an email to the project team.  Please
'log into Lotus Notes after clicking OK."
Maildb.OPENMAIL
'End If
Loop
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = recip
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SAVEMESSAGEONSEND = saveit
'Set up the embedded object and attachment and attach it
If attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachement")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", attachment)
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items
'Folder
MailDoc.SEND 0, recip
 
 
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
Thanks for this. Do you know how to include the user's groupwise signature with the message being sent from Access??
 
Hi All,

Here is the URL for a dev guide for the groupwise module you are using.

http://developer.novell.com/wiki/index.php/Image:GWDevGuide.pdf

I found it really helpful and enabled me to get a lot of extra functionality out of the module. It includes logging in to different accounts (just have to specify username and password).

Definitely worth a read if you are sending mails/tasks with Groupwise from Access.

HTH

Tom
 
Try replacing the line:
Call Groupwise_Mail(TestEmails(), TestAttachments(), TestSubject, TestBody)

with this line:
Call Groupwise_Mail(TestEmails, TestAttachments, TestSubject, TestBody)

You only need the name of the array to be passed to the function. This worked for me!

I am also getting the error error: an invalid argument was passed in the function call. I have tried both variations of the line above and neither works. I get the same error, and the email appears in my email as a work in progress email and blank.

The line the error seems to be raising the bolded line:

Code:
  Set objRecipients = objMessage.Recipients
    For Each Recipient In myRecipients
    [B]    Set objRecipient = objRecipients.Add(Recipient)[/B]
    Next Recipient
 
I am also getting the same problem. I am using GW8 - not sure if this affects things.

Could someone post a working sample DB?

C
 
Hi there
Since I first posted my query and suggestion we have discovered another solution to the Groupwise emailing from an Access database problem.
We are selecting a group of people to email and adding records to a temporary table and then calling the following module. Our recipients are all added as 'BC' in the email and we send to a dummy 'TO' (internal) address. The email is opened for the users to enter the subject and the body of the email. They can also attach files. Works really well.

Function GWemail()
Dim rst As ADODB.Recordset
Dim vCommander As Object
Set vCommander = CreateObject("GroupwiseCommander")
Dim iRet As Integer
Dim ParamStr As String
Dim MyMessageID As String
Dim MyList As String
Dim MyTxt As String
Dim sResult As String
Set rst = New ADODB.Recordset

strSQL = "SELECT emailmerge.Surname, emailmerge.FirstNames, emailMerge.email FROM emailMerge ORDER BY emailMerge.Surname;"
With rst
Set .ActiveConnection = CurrentProject.Connection
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open strSQL
If (rst.EOF = True Or rst.BOF = True) Then
strMsg = "There are no records which meet your criteria"
intStyle = vbOKOnly
strTitle = "Ya Ya Message"

MsgBox strMsg, intStyle, strTitle
Cancel = True
Exit Function
Else
.MoveFirst

Do Until .EOF
If IsNull(!email) = True Or !email = "" Then 'check if email addy is not null - can do this before updating emailMerge file as well
MyNoEmailList = MyNoEmailList & !FirstNames & " " & !Surname & (Chr(13) & Chr(10))
Else
MyList = MyList & !FirstNames & " " & !Surname & " <" & !email & ">; "
End If
.MoveNext
Loop
End If
End With
'Open a new message
iRet = vCommander.Execute("NewMail()", sResult)
MyMessageID = "X00" 'New messages start with this ID

'Address to mylist@dummy.nz which is just a dummy address
MyTxt = "mylist@dummy.nz"
ParamStr = "ItemSetText(""" + MyMessageID + """; 0; """ + MyTxt + """)"
iRet = vCommander.Execute(ParamStr, sResult)

'Fill in BC field from List created above
ParamStr = "ItemSetText(""" + MyMessageID + """; 3; """ + MyList + """)"
iRet = vCommander.Execute(ParamStr, sResult)

'Subject
If IsLoaded("frmTrainingCourses") = True Then
MyTxt = Forms!frmTrainingCourses.Form!cboCourse & " " & Forms!frmTrainingCourses.Form!CourseTitle
Else
MyTxt = ""
End If

ParamStr = "ItemSetText(""" + MyMessageID + """; 9; """ + MyTxt + """)"
iRet = vCommander.Execute(ParamStr, sResult)

'Body Text
MyTxt = "Hello there Everybody"
ParamStr = "ItemSetText(""" + MyMessageID + """; 10; """ + MyTxt + """)"
iRet = vCommander.Execute(ParamStr, sResult)
If MyNoEmailList <> "" Then
sResult = MsgBox(" The following members do not have an email address: " & (Chr(13) & Chr(10)) & MyNoEmailList)
End If
End Function


I hope this works. We are using it a lot & sending to a number of recipients at a time.
cheers
 
I liked the code you have, but when I run it it gives me the error: an invalid argument was passed in the function call. What am I doing wrong?
Thanks.:confused:

The problem was actually with the TestEmailFunc Sub. Specifically the ReDim of the arrays.
Code:
ReDim TestEmails(1) As String

It uses a unfortunately common bad practice of defining only the Upper Bound of the array. The Lower Bound is defined by a default as either 0 or 1. This default can be set for a module using a declaration like this in the declarations section:
Code:
Option Base 1

The system default is zero but the code provided has relied on the Base being set to 1 otherwise it would have needed two values loaded to the array. The invalid argument is caused by the Null in TestEmails(0).

This particular code and be easily fixed by changing both the ReDim lines to this structure:
Code:
ReDim TestEmails(1 To 1) As String


Remember to use best practices in coding:
ALWAYS ReDim both bounds of any array. NEVER rely on the default as zero or the Base declaration.

Also, if you are not setting the bounds of an array within a Sub or Function (such as when receiving an array as an argument) ALWAYS read the Lower Bound and use it in the code accordingly. NEVER rely on it be passed with the default Lower Bound.
 

Users who are viewing this thread

Back
Top Bottom