1
votes

I just need to be pointed in the right direction, on how to send an email using VBA. I have Lotus as an email system which is embedded into our intranet system.

As a try, this code prepares an email and send it via Lotus (installed on pc) :

Dim ns As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim sender, recipient As String
'sender = Forms![LogIn]![TxtEmail]
If (Not IsNull(DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'"))) Then
    recipient = DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'")
    MsgBox "recipient *" & recipient & "*"
    Else
    MsgBox " recipient null"
End If

If Not (ns Is Nothing) Then

     Call ns.InitializeUsingNotesUserName("CN=MyuserName/O=Cmpany", "password")

    Set db = ns.GetDatabase("ServerName", "mail\MyuserName.nsf", False)
    If (Not (db Is Nothing)) Then
        Set doc = db.CreateDocument()
        doc.Form = "Memo"
        doc.SendTo = recipient
        doc.subject = "Email Subject"
        Dim rt As NotesRichTextItem
        Set rt = doc.CreateRichTextItem("Body")
        rt.AppendText ("Body text")
        doc.Send (False)
        Set rt = Nothing
        Set doc = Nothing
        MsgBox "Message Sent."
    Else
    MsgBox "db Is Nothing"
    End If
    Set db = Nothing
    Set ns = Nothing
Else
    MsgBox "ns  Is Nothing"
End If

My question here is how set this code to make the target Lotus the one on our intranet: my login is such "39398C@mycompany.com" and the application is accessed by "http://mail.mycompany.com/mail/username.nsf..."

4
I'm not sure we're understanding something. You have Lotus Notes installed on your PC and it can send mail using the above code. You also have access to iNotes via your Intranet. But it is possible that the Notes client that is installed on your PC is using the very same server that is powering iNotes on your intranet. In fact, that is very commonly the case. Do you know if it is true in your situation, or do you know that they are different servers? If they are the same server, why do you need to change anything? - Richard Schwartz
@RichardSchwartz thank you for your response. In fact, yes I had a Notes client installed on my pc but I 'am not using it even not configured, only iNotes is needed here, my point is to set the code above to connect to my account on the intranet and send the email. When I execute the code it opens the local installed client. - Oumaya

4 Answers

2
votes

Unfortunately this is not possible this way. This "embedded" Lotus Notes as you call it is a simple website. It is called "iNotes" and does not have any dlls installed on your client (unless you install the ActiveX control for IE, but that does not help anything with your problem).

For sending eMails via iNotes you need a complete new method and you need your Domino administrator to help you with it: You could either use a webservice to send your mail (this has to be enabled on the server) or you can use DIIOP (again: DIIOP- Task has to be loaded on server).

To at least compose an email, you could use the mailto: protocol, but you need to set iNotes to be your mailto- protocol- handler:

  1. Open Internet Explorer browser and log into iNotes (http://mail.mycompany.com/mail/username.nsf). Please note that this option is not available at this time to Firefox browser users.
  2. Click the "Preferences" button located in the top right corner.
  3. Find "Default Mail Client" section on the "Basics" tab of the iNotes preferences.
  4. Click the button "Make Default".

Using this approach you cannot send the mail directly but need the user to press "Send".

2
votes

I am not sure what you mean by "I have Lotus as an email system which is embedded into our intranet system".

You need the Notes client installed locally to be able to use COM in your own code. Use the ID file (must be local in the Notes Data directory) for your corporate account amd point to the server on the network for your mailfile.

But you can't point your program to a iNotes instance on a web server, it has to be on a Domino server accessed with a Notes client.

What you could do is to create a new web application on the server, where you have an agent that will read HTTP POST data, create an email and send it out. Then you simply make a HTTP post from your application.

Here are a couple of blog entries I wrote that might help you:

http://blog.texasswede.com/free-code-class-to-read-url-name-value-pairs/

http://blog.texasswede.com/parse-url-in-domino-agent/

2
votes

You should probably change your code to send mail via SMTP instead of using the Notes API objects. Microsoft provides an object model called CDO that I think will help you. See the answer to theis question for details. You will just need the hostname or IP address information to connect to a Domino server in your infrastructure that supports inbound SMTP.

1
votes

Not sure about it, because that code is pretty old as we know use Outlook and I haven't use it in a long while, but that might be some insight :

I seem to remember that if you add doc.From = ns.CommonUserName, this will choose your session automatically!

And the full code :

Dim session As Object
Dim db As Object
Dim doc As Object
Dim attachme As Object
Dim EmbedObj As Object
Dim attachment() As String
Dim i As Integer

Set session = CreateObject("notes.notessession")
Set db = session.GetDatabase("", "")
Call db.OPENMAIL

Set doc = db.CreateDocument

With doc
    .Form = "Memo"
    .sendto = MailDestinataire
    '.copyto = MailDestinataire2
    .Subject = Sujet
    .Body = CorpsMessage
    .From = session.CommonUserName
    .posteddate = Now
    .SaveMessageOnSend = True
End With