我有工作的VBA代码,但我无法将其转换为C#。 我试过了,但是我的C#技能让我失望了。
下面的代码创建新消息并在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 = "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
谢谢!
谢谢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 = "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;
}
答案 0 :(得分:3)
大概是这样的:
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;
}
如果您有可以添加的com对象作为参考,那会更好,但那里可能存在版本问题。另请注意,此代码假定后期绑定。