我有工作的VBA代碼,但我無法將其轉換爲C#。 我試過了,但是我的C#技能讓我失望。將vba轉換爲c# - 請幫忙! Lotus Notes創建新的電子郵件
下面的代碼創建新消息並在Lotus Notes中打開新電子郵件(如果Lotus應用程序處於活動狀態,則使用活動會話)或在Notes未運行時打開新的Notes實例。
您能否協助?
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 = "[email protected]"
CCD = "[email protected]"
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
謝謝!
謝謝competent_tech的解決方案:
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 = "[email protected]";
CCD = "[email protected]";
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;
}
該代碼是否有效?我從來沒有過'沒有人'的頭。 – ChaosPandion
只需將一個COM引用添加到任何組件'Notes.NotesSession'中,並讓Visual Studio爲您生成包裝。我*認爲*它是'domino.dll',但現在它都是一個微弱的記憶。 – vcsjones