从发件人帐户获取电子邮件地址

有没有办法从已login的Outlook帐户“读取”用户电子邮件地址,并在激活此macros时发送电子邮件?

Sub MailSenden() Dim olApp As Object Dim olOldBody As String Rem Email erstellen Set olApp = CreateObject("Outlook.Application") With olApp.CreateItem(0) .GetInspector.Display olOldBody = .htmlBody .To = "carsten.asdf@xxx.yy" .Subject = "Testformular" .Body = "Das ist eine e-Mail" & Chr(13) & _ "Viele Grüße..." & Chr(13) & Chr(13) .Attachments.Add "C:\Users\" & Environ$("USERNAME") & "\Desktop\" & "CSV-Export.csv" .Attachments.Add ActiveWorkbook.FullName .Send End With Kill "C:\Users\" & Environ$("USERNAME") & "\Desktop\" & "CSV-Export.csv" End Sub 

我需要得到“从”电子邮件地址。

编辑1:解决scheme的smtp

 Msgbox CreateObject("Outlook.Application").GetNamespace("MAPI").Session.CurrentUser. _ AddressEntry.GetExchangeUser.PrimarySmtpAddress 

要获取当前用户的电子邮件地址,请使用以下代码。

 With olApp MsgBox .GetNamespace("MAPI").CurrentUser.Address End With 

要从哪个地址select您将发送您的电子邮件,请使用此代码。 这样您就可以在创build的电子邮件中插入"FROM"选项卡。

 With olApp.CreateItem(0) .SentOnBehalfOfName = "YourEmail@yourdomain.com" .GetInspector.Display olOldBody = .htmlBody .To = "carsten.asdf@xxx.yy" .Subject = "Testformular" .Body = "Das ist eine e-Mail" & Chr(13) & _ "Viele Grüße..." & Chr(13) & Chr(13) .Attachments.Add "C:\Users\" & Environ$("USERNAME") & "\Desktop\" & "CSV-Export.csv" .Attachments.Add ActiveWorkbook.FullName .Send End With 

请注意,您应该With olApp.CreateItem(0)行代码将.SentOnBehalfOfName = "YourEmail@yourdomain.com"

尝试MailItem.Session.CurrentUser.AddressMailItem.SenderEmailAddress都应该工作。

您可能需要从Exchange帐户转换为SMTP,请执行以下操作:

我怎样才能得到发件人的电子邮件地址在VB.NET中使用Outlook.MailItem?