I have working VBA code, but I can’t convert it to C#.
I have tried, but my C# skills are failing me.
The code below creates new message and opens new email in Lotus Notes (using active session if Lotus application is active) OR opens a new instance of Notes if Notes is not running.
Could you please assist?
Sub SendMail()
Dim Notes As Object
Dim db As Object
Dim WorkSpace As Object
Dim UIdoc As Object
Dim userName As String
Dim MailDbName As String
Set Notes = CreateObject("Notes.NotesSession")
userName = Notes.userName
MailDbName = Left$(userName, 1) & Right$(userName, (Len(userName) - InStr(1, userName, " "))) & ".nsf"
Set db = Notes.GetDataBase(vbNullString, MailDbName)
Set WorkSpace = CreateObject("Notes.NotesUIWorkspace")
Call WorkSpace.ComposeDocument(, , "Memo")
Set UIdoc = WorkSpace.currentdocument
Recipient = "test@email.com"
CCD = "test2@email.com"
Call UIdoc.FieldSetText("EnterSendTo", Recipient)
Call UIdoc.FieldSetText("EnterCopyTo", CCD)
Subject1 = "Subject")
Call UIdoc.FieldSetText("Subject", Subject1)
Call UIdoc.GotoField("Body")
Call UIdoc.INSERTTEXT("This text goes to body")
Application.CutCopyMode = False
Set UIdoc = Nothing
Set WorkSpace = Nothing
Set db = Nothing
Set Notes = Nothing
END SUB
Thank you!
Thank you competent_tech for solution:
public void SendMail()
{
dynamic Notes = null;
object db = null;
dynamic WorkSpace = null;
dynamic UIdoc = null;
string userName = null;
string MailDbName = null;
Notes = Activator.CreateInstance(Type.GetTypeFromProgID("Notes.NotesSession"));
userName = Notes.userName;
MailDbName = userName.Substring(0, 1) + userName.Substring(userName.Length - ((userName.Length - (userName.IndexOf(" ", 0) + 1)))) + ".nsf";
db = Notes.GetDataBase(null, MailDbName);
WorkSpace = Activator.CreateInstance(Type.GetTypeFromProgID("Notes.NotesUIWorkspace"));
WorkSpace.ComposeDocument("", "", "Memo");
UIdoc = WorkSpace.currentdocument;
Recipient = "test@email.com";
CCD = "test2@email.com";
UIdoc.FieldSetText("EnterSendTo", Recipient);
UIdoc.FieldSetText("EnterCopyTo", CCD);
Subject1 = "Subject";
UIdoc.FieldSetText("Subject", Subject1);
UIdoc.GotoField("Body");
UIdoc.INSERTTEXT("This text goes to body");
UIdoc = null;
WorkSpace = null;
db = null;
Notes = null;
}
It’s going to be roughly:
It would be better if you had the com object that you could add as a reference, but there could be versioning issues there. Also note that this code assumes late binding.