Macros and Programming


CardboxForumsMacros and Programming > "Sending single email from Outlook 2003"

Sending single email from Outlook 2003

Trying to implement macro on help point 529

Current user: [none]
Register / Log In · Help

Posted By Post


18-Dec-2012 11:09

Hi there

I have installed CDO and have changed the registry key ThreadingModel value from Both to Apartment as suggested in the guide. The macro is now activating Outlook as when I run it is asks me to choose an Outlook profile. Immediately after this it comes up with the error:

[Collaboration Data Objects -[E_INVALIDARG(80070057)]]
Position in the Macro Line 45, Character 2

Does anyone have any ideas please?


' Names of Cardbox fields
const fieldTo = "EMAIL"
const fieldSubject = "SUBJECT"
const fieldMessageText = "EMAILTEXT"

' Function definitions required by the macro
Dim app
Function ConnectToEmail()
 If IsEmpty(app) Then
   Set app = CreateObject("MAPI.Session")
   ' If the above line causes an error, then
   ' EITHER Outlook is not installed and the default email program
   ' OR CDO is not installed
   ' OR you are suffering from the Microsoft CDO bug: see
   ' http://support.microsoft.com/default.aspx?scid=kb;EN-US;q239096
   ' for details.
   End If
 ConnectToEmail = Not (app Is Nothing)
 End Function

Function StripMailtoPrefix(Email)
 If Left(Email,7)="mailto:" Then
  End If
 End Function
Function SendOneMessage(Email,Subject,Fulltext)
 if Not ConnectToEmail Then
   MsgBox "Cannot connect to Outlook"
   Exit Function
   End If
 ' create a message and fill in its properties
 Set objMessage = app.Outbox.Messages.Add
 objMessage.Subject = Subject
 objMessage.Text = Fulltext
 ' create the recipient
 Set objOneRecip = objMessage.Recipients.Add
 objOneRecip.Address = EMAIL <----------- LINE 45
'"SMTP:" & StripMailtoPrefix(Email)
 objOneRecip.Type = 1 ' 1 = main recipient
 ' send the message.
 End Function

Function SendMessageForRecord(rec)
 Set flds=rec.Fields
 End Function

' Here is the text of the macro itself.

Thanks in advance :)


18-Dec-2012 11:15

We currently use the following which does everything we need apart from being able to format the body text. Any way that we could add HTML would be perfect but I don't think that is possible.

Launch "mailto:" & Fields("REPORTS_SENT_TO") & "?Subject=" & CLIP & "" & "&Body=" & MSG & ""

Charles Welling

18-Dec-2012 12:02

I'm afraid I cannot answer your question, but considering you use Outlook then it might be so that your e-mails are sent through Exchange. If that's the case you can have Cardbox send the e-mails straight to Exchange, which is a whole lot easier, because it bypasses Outlook.
Below you will see an example of a very short macro that sends an e-mail to Exchange. Where the first line reads "MyFileserver", you would have to enter the name of the server which runs Exchange.

You can use HTML; see line 3.
In this example the HTML is written by Cardbox using a format "MyFormatinHTML". If necessary you can consult the Helpfile how to do this.


set sender = EmailSender("John Doe <j.doe@myoffice.com", "MyFileserver") ' Replace MyFileserver with the actual name
sender.AddRecipient "j.johnson@anotheroffice.com",0
sender.Subject = "Try this."


18-Dec-2012 13:56

Thanks for your reply Charles, this could work for me.

However, I'm getting the following error message:

503 5.5.2 Need rcpt command

Any ideas?

Thanks again :)


18-Dec-2012 18:43

I use Cardbox for sending mail on two ways:
- For a single email based on the current record or so, I generate a new email which can be send using Outlook. I can add or change also things in the generated email I want to send.
Directly sending by the macro using Outlook is not possible without extra clicking the security things of Outlook. If you also want to send by Outlook the generated email by the macro, you can decide installing a free quick and dirty programme (ClickYes) which clicks the security buttons automatic. You can also avoid the security using Sendkeys commands.
- For bulk html email I use CDO and send the mail by a macro does send the email without Outlook. I use then the smtp server of my provider. However, in some situations the smtp server is blocked for doing this (easy sending spam...). Because my provider has not blocked it, I can use it. If you want to use this you have to test this.
The error rcpt msg I recognize. However I do not remember if I fixed it or I did find a workaround.

Charles Welling

18-Dec-2012 20:47

No, I'm sorry. I've never seen this message. A quick search on the Internet tells me "You tell the mail server who the recipient of your message is by using the RCPT command". But that is supposed to be taken care of by "sender.AddRecipient" (I guess).

Quick Reply

Please log in or register before trying to post a reply.

© 2010 Cardbox Software Limited   Home