Lotus Notes Generic Mailbox VBA Code

Dear All,

I am a fresh starter on the VBA programming, I was able to create a VBA code to send e-mail from a generic mailbox. My only issue is that if the e-mail is sent to a non-lotus notes client, the generic mailbox name (from) disappears and it looks like the e-mail was sent from my personal mailbox.

As a note, the e-mail looks fine in the sent folder. However, when I test it to see how I receive it on an outlook client my personal e-mail appears as "From.

VBA Code:

Sub Emails()

For i = 2 To 10000

nume = 0

If Worksheets("Sheet1").Cells(i, 1) = "" Then
Exit For
End If

'For j = 2 To 26
'myBodyText = myBodyText & Worksheets("mail").Cells(j, 1) & Chr$(13)
'Next j

nume = Worksheets("Sheet1").Cells(i, 1)
numeCC = Worksheets("Sheet1").Cells(i, 6)
subiect = "Comunicazione informativa ai Fornitori Gruppo Zurich Italia riguardante le informazioni da includere nelle fatture inviateci"

Call SendNotesMail(subiect, nume, numeCC, True)

Next i

End Sub

Public Sub SendNotesMail(ByVal Subject As String, _
ByVal Recipient As String, ByVal CC As String, ByVal SaveIt As Boolean)

On Error GoTo notsent

    Dim Maildb As Object '//The database
    Dim UserName, usersig  As String '//The username
    Dim MailDbName As String '///The name of the database
    Dim MailDoc As Object '//The mail document
    Dim Session As Object '//The Notes Session
    Dim EmbedObj As Object '//Object

    '//Start Session
    Set Session = CreateObject("Notes.NotesSession")
    UserName = Session.UserName
    usersig = Session.CommonUserName
    '//Open the database
    Set Maildb = Session.GETDATABASE("Server Here", "NSF File Here")
     If Maildb.IsOpen = True Then
          '//Ready to mail!
     End If
    '//Create mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    MailDoc.SendTo = Recipient
    MailDoc.CopyTo = CC
    MailDoc.Subject = Subject
    MailDoc.Body = Sheets("Sheet2").Range("A1").Value

    MailDoc.DeliveryReport = "B"
    'Persuade Notes to send/display alternate address
    MailDoc.From = """S&P Communications"" <s&p.communications@zurich.com>" 'Sent by"
    MailDoc.SendFrom = "ap.it@zurich.com"     'Sent by E-Mail Address on REPLY"
    MailDoc.DisplayFrom = "S&P Communications<s&p.communications@zurich.com>"  'Group Email Display Name"
    MailDoc.Principal = "S&P Communications<s&p.communications@zurich.com>" 'Group Email Address on REPLY"
    MailDoc.Signed = False

    '//Attach objects and attachments
    'If Attachment <> "" Then
    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment1")
    Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", "P:\Global\Ariba Helpdesk\Reports\Project\Communicazione Zurich per Fornitori.pdf", "Letter")

    'End If
    MailDoc.PostedDate = Now()
    MailDoc.SEND 0, Recipient
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
    Exit Sub
    sended = False
    Resume ResDocument
End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:

There is a "solution" posted at the official Notes/Domino 6 and 7 Forum:

[ (http://www-10.lotus.com/ldd/nd6forum.nsf/0/13706561dc7d693f852570af0062fcec?OpenDocument ]

The "Principal" field must be formatted in this manner:

"From User" <fromuser@xyz.com@DOMAIN>

Your field value seems to be missing the quote characters & the @DOMAIN suffix.

Does that help?

--- Forum post text follows ---

RE: Sending an email from LotusScript
Posted by Jill A Wilson on 4.Nov.05 at 14:01 using a Web browser
Category: Applications Development
Release: 6.5.4
Platform: All Platforms

Thank you Julie -
What a wonderful help resource.
I found the problem to be that I was not formatting the Principle field properly for external emails.
The correct code is:
Principle = "customerservice@xyz.com"
 maildoc.Form = "Memo"
 ' Principal overrides From
 ' Must be formatted as below and must include the domain @xyz.com
 ' Format should equal: "From User" <fromuser@xyz.com@DOMAIN>
 maildoc.Principal = |"Customer Service" <| + Principle + |@xyz.com>|
 maildoc.From = Principle
 maildoc.AltFrom = Principle
 maildoc.SendFrom = Principle
 maildoc.INetFrom = Principle
 maildoc.tmpDisplaySentBy = Principle
 maildoc.tmpDisplayFrom_Preview = Principle
 maildoc.DisplaySent = Principle
Thank you all for your help.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sjef BosmanGroupware ConsultantCommented:
I'm afraid that that's not the solution. It won't allow you to completely remove the sender from the message, because From will always be filled in by the server/router. There's only one way to do it using only VB: don't use document.Send, but put the mail directly into the mail.box database.
[ fanpages ]IT Services ConsultantCommented:
Don't be afraid!  It sounds like you have more experience than me with this (that, to be fair, couldn't be difficult).

However, whilst I was looking for details I found this web page that supports your suggestion:

[ http://blog.texasswede.com/lotusscript-mail-notification-class/ ]

Lotusscript: Mail Notification Class

Posted on November 2, 2011
by Karl-Henry Martinsson
Back in August 2009, I posted a small class I had created to make it easier for me to create mail notifications in my Lotusscript agents. Since then I have improved on it, and I wanted to post the latest version. One recent feature I added is to send external mail to the internet that looks like it is coming from a different user. This is often needed when you have an agent signed with a developer/admin ID, but you want the mail to look like it is coming from a particular department or user.

This is done by using the (unsupported) method of saving the document in mail.box instead of using doc.Send() to mail it directly. What I found is that you should use mail.box on the same server as the agent is running on, you can not access mail.box on a different server. The code reflect this.
Other new features are support for doclinks, attachments and an option to display a warning message at the end that the mail comes from an un-monitored role account. This warning is actually turn on by default.

(VBA code follows this text online)
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Sjef BosmanGroupware ConsultantCommented:

I'd have posted more but my battery was almost empty... The online code is very much alike VBA but in fact it's LotusScript. It won't take you long to find out how it's done in order to be able to modify your own VBA code. I tried to find some sample code online, to no avail.
cristianpriftiAuthor Commented:
Thank you verrryyy muuuuchhhhh!
I almost wanted to break the keyboard :)

It works very good now!
Sjef BosmanGroupware ConsultantCommented:
Ah, if it suits you: fine! But do you see your name when you have a peek in the HTML source of the mail?
[ fanpages ]IT Services ConsultantCommented:
Sorry, sjef_bosman, yes, my mention of "VBA" was erroneous.  Well spotted.

You're very welcome, cristianprifti.  Count to ten & take a deep breath! :)

Also, please look at sjef_bosman's warning, in case your name is still present.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.