現在、それぞれに独自の電子メールアドレスが関連付けられた2つのLotus Notesデータベースがあります。予想通り、最初のデータベースから自分のGmailアカウントに電子メールを送信すると、「From:[email protected]」と表示され、2番目のデータベースを使用して送信すると、メッセージは「From:notesAccount2 @ db2私のGmailで.com "間違った電子メールアドレスからExcel VBAの送信を使用してIBM Lotus Notes電子メールを送信
を開き、特定のキーワードを含む電子メールを受信トレイで検索し、その電子メールから電子メールアドレスを抽出します。その後、その第2のデータベースに新しい文書を作成し、受信者の名前、件名、本文などを挿入し、電子メールを送信して、送信済みフォルダに保存します。すべてがこの時点までスムーズに機能します。
ただし、このVBAメソッドを使用して2番目のデータベースから自分のGmailアカウントにメールを送信すると、電子メールはGmailの最初のデータベースに関連付けられた「From:[email protected]」として表示されます。
なぜこれが起こっているのかわかりません。 VBAとLotus Notes、およびLotus Notesサーバー/データベースとの間の相互作用に関する一般的な知識はほとんどありません。 最初のデータベースは技術的に私がアクセスできるのは私のデフォルトのデータベースで、2番目のデータベースは後で追加され、複数の人がアクセスできます。それが適切かどうかわかりません。
助けていただければ幸いです!ありがとう。
注:このコードをコピーし、適応SOの一部を含むいくつかのソースから、IBMおよび他のNotesソースを、そして何か他のものは、Googleが http://www.fabalou.com/vbandvba/lotusnotesmail.asp
http://www-01.ibm.com/support/docview.wss?uid=swg21178583
を含め、私の方法を投げました。コード:(これはサーバー名とメールファイル名を取り除いたものです)
Sub ReadNotesEmail()
Dim sess As Object
Dim db As Object
Dim folder As Object
Dim docNext As Object
Dim memoSenders As Variant
Dim newEmail As Object
Dim view As Object
Dim entry As Object
Dim entries As Object
Dim templateEmail As Object
Dim mailServer As String
Dim mailFile As String
Dim folderName As String
Dim todayDate As String
Dim memoBody As String
Dim senderEmail As String
Dim emailStartPos As Integer
Dim emailEndPos As Integer
'This program will search a particular folder in a Notes database that I designate.
'It will search that folder for emails that contain certain key words. Once it finds
'an email that fits, it will grab the sender's email address (written in the body, not
'in the 'from') and send them an email.
'Name of folder to search for emails
folderName = "($Inbox)"
'Create a Lotus Notes session and open it (will require password)
Set sess = CreateObject("Lotus.NotesSession")
sess.Initialize ("")
'Set the mail server, mail file, and database. This will be the tricky part as I need this to
'look at the second mail server as opposed to the default mail server of jdyagoda
Set db = sess.GETDATABASE("***name of second Notes server***", "***name of second mail file***")
'Open the mail database in notes
If Not db.IsOpen = True Then
Call db.Open
End If
Set folder = db.GetView(folderName)
'Now look through the emails one at a time with a loop that ends when no emails are left.
'If an email contains the key word, look for the email address of the person who submitted
'the contact-us form. It follows the string "Email:" and preceeds
'the string "Phone:".
Set doc = folder.GetFirstDocument
Do Until doc Is Nothing
Set docNext = folder.GETNEXTDOCUMENT(doc)
memoBody = LCase(doc.GetItemValue("body")(0))
If (memoBody Like "*") Then 'This is where you designate the keyword
'Here's where you extract the email address - taken out for the purpose of this SO question
'senderEmail = [email protected]
'Now create a new email to the intended recipient
Set newEmail = db.CREATEDOCUMENT
Call newEmail.ReplaceItemValue("Form", "Memo")
Call newEmail.ReplaceItemValue("SendTo", senderEmail)
Call newEmail.ReplaceItemValue("Subject", "Thank you for your email")
Call newEmail.ReplaceItemValue("body", "Test Body 1. This is a test.")
newEmail.SAVEMESSAGEONSEND = True
'Send the new email
Call newEmail.ReplaceItemValue("PostedDate", Now()) 'Gets the mail to appeaer in the sent items folder
Call newEmail.SEND(False)
End If
Set doc = docNext
Loop
End Sub
です。返信いただきありがとうございます。問題は確かに意味があります。残念なことにITの人たちは、少し古い私が第2のアカウントに直接ログインする方法はない、と伝えています。あなたがリンクしている潜在的な回避策には感謝しています(ただし、非常にうまく書かれています)。しかし、私がやろうとしていることは私の頭をはるかに超えていると思います。私はそれがどのように働くのだろうが、例えば、「New」をクリックして2番目のアカウントから新しいメールを手動で(VBAではなく)作成して送信すると、2番目のアカウントはどのように送信者としてリストされますか?既定のクラスを使用してVBAでコピーする方法はありませんか? – jdyagoda
たとえば、プログラムを使って各電子メールを送信する代わりに、その電子メールを下書きフォルダに保存してから、コードを入力したすべての下書きを手動で送信することはできますか?その2番目のアカウントから手動で送信しているので、2番目に表示されている電子メールを送信する必要がありますか? – jdyagoda
あなたが参照しているのは、Notesクライアントの機能です。このクライアントは、現在開いているメールデータベースの所有者フィールドを見つけてメールを送信するために使用します。 NotesクライアントはKarl-Henryの説明に従っているため、この魔法は正確に機能します。メッセージをmail.boxファイルに直接書き込みます。この機能は、VBAから使用しているNotes COMクラスのSend()メソッドでは使用できません。これは、クラスの開発者が(意図的にまたは偶然に)送信者を偽装することを困難にする意図的な選択です。 –