Help With Redemption

marky_dp

Registered User.
Local time
Today, 12:51
Joined
Jan 5, 2006
Messages
24
Hi all, i've just downloaded redemption and set a reference to it, but am unsure how to adapt my code so that it makes use of it and by-passes the access/outlook email warning.

If any one could have a pop at modifying my code so that it makes use of redemption that would be greatly appreciated.

Thanks in advance

Send Button - On Click Code:

Private Sub SendButton_Click()
'Send Email when user clicks on button


'Make a connection to the db
Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = myConnection

'Define variables for outlook application
Dim appOutlook As Outlook.Application 'Refers to Outlook's Application object.
Dim appOutlookMsg As Outlook.MailItem 'Refers to an Outlook e-mail message.
Dim appOutlookRecip As Outlook.Recipient 'Refers to an Outlook e-mail recipient.


'More general variables.
Dim mySQL As String, eMailAddress As String, whereClause As String
Dim countEm As Integer, myMsg As String

countEm = 0 'keep track of the number of messages sent.

'Start building the SQL statement for the recordset.
mySQL = "SELECT * FROM CustomerTBL"

'Create search condition based on selected option button.
'SendOptions.Value refers to the option button selected near bottom of form.
Select Case SendOptions.Value

Case 1 'All Customers
whereClause = " WHERE CustomerEmail Is Not Null"
Case 2 'Single customer from combo box
whereClause = " WHERE CustomerID= " & LookForID.Column(0)

End Select

'Finish the SQL statement.
mySQL = mySQL & whereClause

'Now let's open up the recordset and start going through, record-by-record.
myRecordSet.Open mySQL, , adOpenStatic, adLockOptimistic
'Bail out if recordset gets no records.
If myRecordSet.RecordCount < 1 Then
MsgBox ("There Are No Records That Meet The Criterion. No Messages Have Benn Sent.")
Exit Sub
End If
myRecordSet.MoveFirst

'Create an Outlook session in the background.
Set appOutlook = CreateObject("Outlook.Application")

'Now Set objSafeMail instead NEW CODE none taken out here reminder
Set objSafeMail = New Redemption.SafeMailItem



Do Until myRecordSet.EOF 'For each record in myRecordset...

'Get the e-mail address from current record of myRecordset.
eMailAddress = myRecordSet.Fields("CustomerEmail")

'If there's a # character in the eMail address...
If InStr(1, eMailAddress, "#") > 0 Then
'...then chop off the # and everything that follows it.
eMailAddress = Left(eMailAddress, InStr(1, eMailAddress, "#") - 1)
End If


'Create a new, empty e-mail message.
Set appOutlookMsg = appOutlook.CreateItem(olMailItem)


With appOutlookMsg 'Using the new, empty message...


' Address the new message.
Set appOutlookRecip = .Recipients.Add(eMailAddress)


appOutlookRecip.Type = olTo 'Sets message to normal outgoing e-mail message.

' Fill in the Subject line and main body of message.
.Subject = Me![Subject] 'Fill in the subject line.
.Body = Me![MessageBody] 'Fill in the message body.
'Add attachments, if any, to the e-mail message.
If Len(Me![Attachment]) > 0 Then
.Attachments.Add (Me![Attachment])
End If

.Send 'Send the completed message.

End With

myRecordSet.MoveNext 'Next record in recordset
countEm = countEm + 1 'Keeps track of number of messages printed for later display.
Loop 'Repeat with next record, if not eof.

myRecordSet.Close 'All records processed when loop done. Close recordset.

'Display feedback message.
myMsg = countEm & " Message(s) Sent To Outlook's Outbox"
myOKBox (myMsg)
'All done when loop done. Clean up and say bye-bye.
Set myRecordSet = Nothing
Set appOutlookMsg = Nothing
Set appOutlook = Nothing
Set myConnection = Nothing

End Sub
 
cheers for the tip Sergeant,

Have put in a bit of extra code but i'm still getting the security warning (although 'yes' only needs clicking once now) and my emails are now ending up in the drafts folder, whereas they were in put in the outbox before.

Any help would be greatly appreciated here, as i am completely lost,

cheers

Private Sub SendButton_Click()
'Send Email when user clicks on button


'Make a connection to the db
Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = myConnection

'Define variables for outlook application
Dim appOutlook As Outlook.Application 'Refers to Outlook's Application object.
Dim appOutlookMsg As Outlook.MailItem 'Refers to an Outlook e-mail message.
Dim appOutlookRecip As Outlook.Recipient 'Refers to an Outlook e-mail recipient.

Dim objSafeMail As Redemption.SafeMailItem

'More general variables.
Dim mySQL As String, eMailAddress As String, whereClause As String
Dim countEm As Integer, myMsg As String

countEm = 0 'keep track of the number of messages sent.

'Start building the SQL statement for the recordset.
mySQL = "SELECT * FROM CustomerTBL"

'Create search condition based on selected option button.
'SendOptions.Value refers to the option button selected near bottom of form.
Select Case SendOptions.Value

Case 1 'All Customers
whereClause = " WHERE CustomerEmail Is Not Null"
Case 2 'Single customer from combo box
whereClause = " WHERE CustomerID= " & LookForID.Column(0)

End Select

'Finish the SQL statement.
mySQL = mySQL & whereClause

'Now let's open up the recordset and start going through, record-by-record.
myRecordSet.Open mySQL, , adOpenStatic, adLockOptimistic
'Bail out if recordset gets no records.
If myRecordSet.RecordCount < 1 Then
MsgBox ("There Are No Records That Meet The Criterion. No Messages Have Benn Sent.")
Exit Sub
End If
myRecordSet.MoveFirst

'Create an Outlook session in the background.
Set appOutlook = CreateObject("Outlook.Application")

Do Until myRecordSet.EOF 'For each record in myRecordset...

'Get the e-mail address from current record of myRecordset.
eMailAddress = myRecordSet.Fields("CustomerEmail")

'If there's a # character in the eMail address...
If InStr(1, eMailAddress, "#") > 0 Then
'...then chop off the # and everything that follows it.
eMailAddress = Left(eMailAddress, InStr(1, eMailAddress, "#") - 1)
End If


'Create a new, empty e-mail message.
Set appOutlookMsg = appOutlook.CreateItem(olMailItem)


With appOutlookMsg 'Using the new, empty message...

' Address the new message.
Set appOutlookRecip = .Recipients.Add(eMailAddress)


appOutlookRecip.Type = olTo 'Sets message to normal outgoing e-mail message.

' Fill in the Subject line and main body of message.
.Subject = Me![Subject] 'Fill in the subject line.
.Body = Me![MessageBody] 'Fill in the message body.
'Add attachments, if any, to the e-mail message.
If Len(Me![Attachment]) > 0 Then
.Attachments.Add (Me![Attachment])
End If
'Now Set objSafeMail instead NEW CODE none taken out here reminder

appOutlookMsg.Save
Set objSafeMail = CreateObject("Redemption.SafeMailItem")
objSafeMail.Item = appOutlookMsg
objSafeMail.Send

'.Send 'Send the completed message.

End With

myRecordSet.MoveNext 'Next record in recordset
countEm = countEm + 1 'Keeps track of number of messages printed for later display.
Loop 'Repeat with next record, if not eof.

myRecordSet.Close 'All records processed when loop done. Close recordset.

'Display feedback message.
myMsg = countEm & " Message(s) Sent To Outlook's Outbox"
myOKBox (myMsg)
'All done when loop done. Clean up and say bye-bye.
Set myRecordSet = Nothing
Set appOutlookMsg = Nothing
Set appOutlook = Nothing
Set myConnection = Nothing

Set objSafeMail = Nothing


End Sub
 
Right, I've managed to (almost) sort everything out. There is just ione problem getting in the way now and that is that the code wont send to multiple email address. Instead it produces the following run-time error:

Run-time error ‘-2147024891 (80070005)’:

IMessage::ModifyRecipients returned MAPI_E_NO_ACCESS

The code works a treat for sending individual email address but goes ape when you try to send a mail to all your contacts. Again if someone could take the time to have a look at the code and try and figure out whats going on that would be appreciated.

cheers

Private Sub Command23_Click()

'Make a connection to the db
Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = myConnection

'General variables.
Dim mySQL As String, eMailAddress As String, whereClause As String
Dim countEm As Integer, myMsg As String

'New Variables Added
Dim SafeMail As Variant
Dim myOlApp As Variant
Dim myItem As Variant
Dim myRecipient As Variant

'Set the variables
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(0)
Set SafeMail = CreateObject("Redemption.SafeMailItem")
Set SafeMail.Item = myItem


'Start building the SQL statement for the recordset.
mySQL = "SELECT * FROM CustomerTBL"

'Create search condition based on selected option button.
'SendOptions.Value refers to the option button selected near bottom of form.
Select Case SendOptions.Value

Case 1 'All Customers
whereClause = " WHERE CustomerEmail Is Not Null "

Case 2 'Single customer from combo box
whereClause = " WHERE CustomerID= " & LookForID.Column(0)

End Select

'Finish the SQL statement.
mySQL = mySQL & whereClause


'Now let's open up the recordset and start going through, record-by-record.
myRecordSet.Open mySQL, , adOpenStatic, adLockOptimistic

'Bail out if recordset gets no records.
If myRecordSet.RecordCount < 1 Then

MsgBox ("There Are No Records That Meet The Criterion. No Messages Have Benn Sent.")

Exit Sub

End If

'Go To first item in the record set
'myRecordSet.MoveFirst

'For each record in myRecordset...
Do Until myRecordSet.EOF

'Get the e-mail address from current record of myRecordset.
eMailAddress = myRecordSet.Fields("CustomerEmail")

'If there's a # character in the eMail address...
If InStr(1, eMailAddress, "#") > 0 Then

'...then chop off the # and everything that follows it.
eMailAddress = Left(eMailAddress, InStr(1, eMailAddress, "#") - 1)

End If


With SafeMail

Set myRecipient = .Recipients.Add(eMailAddress)

myRecipient.Type = olTo


' Fill in the Subject line and main body of message.
.Subject = Me![Subject] 'Fill in the subject line.
.Body = Me![MessageBody] 'Fill in the message body.
'Add attachments, if any, to the e-mail message.
If Len(Me![Attachment]) > 0 Then
.Attachments.Add (Me![Attachment])
End If

.Send

End With

'Next record in recordset
myRecordSet.MoveNext

'Keeps track of number of messages printed for later display.
countEm = countEm + 1

'Repeat with next record, if not eof.
Loop

myRecordSet.Close 'All records processed when loop done. Close recordset.

'Display feedback message.
myMsg = countEm & " Message(s) Sent To Outlook's Outbox"
myOKBox (myMsg)

Set myOlApp = Nothing
Set SafeMail = Nothing

End Sub
 
is there any news on this as I'm having trouble with sending to multiple email addresses

many thanks
 
Try actually contacting the author of Redemption via E-mail. He's very good at responding within 24 hours, and can help you troubleshoot your code.
 
Or you could try using CDO instead of a redemption.dll
 
That's assuming, of course, that your I.T. hasn't blocked SMTP requests and/or port 25. If your actions are restricted to using the Outlook Object Model, then you still need the Redemption.dll or a similar tool to bypass the warnings.
 
That's assuming, of course, that your I.T. hasn't blocked SMTP requests and/or port 25. If your actions are restricted to using the Outlook Object Model, then you still need the Redemption.dll or a similar tool to bypass the warnings.

Correct, except for the port, you can define which port to use.
 
That's assuming, of course, that the server to which you are connecting allows SMTP requests from a port other than 25.

Also, if SMTP requests are blocked, in general, you're SOL.
 

Users who are viewing this thread

Back
Top Bottom