C# um E-Mail Senden mit Outlook
Arbeite ich in der Konsole Anwendung, und ich bin mit dem unter c# - code, E-mail senden, automatisch auf eine Schaltfläche click-Ereignis,
public void SendMail()
{
////Create the Outlook application by using inline initialization.
Outlook.Application oApp = new Outlook.Application();
////Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
//Add a recipient.
//TODO: Change the following recipient where appropriate.
Outlook.Recipients oRecips = oMsg.Recipients;
List<string> oTORecip = new List<string>();
List<string> oCCRecip = new List<string>();
oTORecip.Add("[email protected]");
oCCRecip.Add("[email protected]");
foreach (string t in oTORecip)
{
Outlook.Recipient oTORecipt = oRecips.Add(t);
oTORecipt.Type = (int)Outlook.OlMailRecipientType.olTo;
oTORecipt.Resolve();
}
foreach (string t in oCCRecip)
{
Outlook.Recipient oCCRecipt = oRecips.Add(t);
oCCRecipt.Type = (int)Outlook.OlMailRecipientType.olCC;
oCCRecipt.Resolve();
}
//Set the basic properties.
oMsg.Subject = "TestMail- " + DateTime.Today.ToString("MM/dd/yyyy");
oMsg.HTMLBody = "<html>" +
"<head>" +
"<title>TestMail</title>" +
"</head>" +
"<body style='background-color:#E6E6E6;'>" +
"<div style='font-family: Georgia, Arial; font-size:14px; '>Hi,<br /><br />" +
"PFA<br />" +
"This is Test Mail.Please Ignore.<br /><br /><br /><br /><br />" +
"Thanks & Regards<br />" +
"test"+
"</div>" +
"</body>" +
"</html>";
string date = DateTime.Today.ToString("MM-dd-yyyy");
//Add an attachment.
//TODO: change file path where appropriate
String sSource = "D:\\Test\\test_" + date + ".xlsx";
String sDisplayName = "MyFirstAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
//If you want to, display the message.
//oMsg.Display(true); //modal
//Send the message.
oMsg.Save();
oMsg.Send();
//Explicitly release objects.
oTORecip = null;
oCCRecip = null;
oAttach = null;
oMsg = null;
oApp = null;
}
dieser code ist in Ordnung.Ich will um die mail zu versenden mit einem anderen account.Wie man die From-Adresse im Obigen code?
Ist es möglich, dies zu tun?was ist der c# - code muss ich verwenden um die mail zu senden im Auftrag von someother-Konto mithilfe von c# - code?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Set MailItem.SendUsingAccount-Eigenschaft auf oMsg
http://msdn.microsoft.com/en-us/library/office/ff869311%28v=office.14%29.aspx
können Sie nur von der Anwendung.Sitzung.Konten Sammlung.
oder möglicherweise check
MailItem.SentOnBehalfOfName
http://msdn.microsoft.com/en-us/library/office/ff862145%28v=office.14%29.aspx
(für exchange)
Gibt es einige ähnliche Beiträge:
Die Automatisierung von Outlook - Ändern-Absender-Konto
Senden verzögern, Nachrichtenübermittlung und ändern der Standard-account mit Powershell
BEARBEITEN
Folgende code ist ok mit intellisense, überprüfen Sie Ihren DLL-version. Geprüft mit v 14 und v 12 der Outlook-PIA.
Paket heruntergeladen
http://www.microsoft.com/en-us/download/details.aspx?id=43664
Es scheint, Sie sind mit einigen anderen assembly-DLL, weil für mich die Aussage "mithilfe von Microsoft.Office.Interop;" funktioniert nicht bei allen.