私はExchange Web Services Managed API 1.1を使用してExchange Server 2010に接続し、受信した新しい電子メールを確認しています。これで、.msgファイルのコピーをディスク上のフォルダに保存します。EWS APIを使用してmsgファイルにメールを保存します。
私は統合するために有料の第三者を使用したくありません。
ご協力いただければ幸いです。
私はExchange Web Services Managed API 1.1を使用してExchange Server 2010に接続し、受信した新しい電子メールを確認しています。これで、.msgファイルのコピーをディスク上のフォルダに保存します。EWS APIを使用してmsgファイルにメールを保存します。
私は統合するために有料の第三者を使用したくありません。
ご協力いただければ幸いです。
EWSを使用するMSGファイルのネイティブサポートはありません。厳密にはOutlook形式です。
MSG仕様は、http://msdn.microsoft.com/en-us/library/cc463912%28EXCHG.80%29.aspxで公開されています。理解するのが少し複雑ですが、できることはありません。メッセージのすべてのプロパティをプルダウンし、それをOLE構造化ファイル形式にシリアル化する必要があります。それは簡単な仕事ではありません。
サードパーティ製のライブラリを使用する方がいいかもしれません。それ以外の場合は、達成するのが大変な作業かもしれません。
.eml
形式で保存していただければ、EWSとサードパーティのライブラリを使用せずに非常に簡単に行うことができます。 .eml
ファイルには同じ情報がすべて含まれ、Outlookでは.msgと同じ方法で(および他のプログラムによっても)開くことができます。コードのクリーンアップ
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = message.MimeContent;
FileStream fs = new FileStream("c:\test.eml", FileMode.Create);
fs.Write(mc.Content, 0, mc.Content.Length);
fs.Close();
:EML形式はオプションとPHPの場合
message.Load(new PropertySet(ItemSchema.MimeContent));
var mimeContent = message.MimeContent;
using (var fileStream = new FileStream(@"C:\Test.eml", FileMode.Create))
{
fileStream.Write(mimeContent.Content, 0, mimeContent.Content.Length);
}
私はこれがずっと間に合ったと知っていますが、あなたの答えに感謝します。私に多くの時間を救った。 – Fox
合意。これはとても役に立ちました!私はちょうどusingステートメントを使用するために少し変更しました: using(FileStream fileStream = File.Open(@ "C:\ message.eml"、FileMode.Create、FileAccess.Write)) { message.Load(新しいPropertySet (ItemSchema.MimeContent)); MimeContent mc = message.MimeContent; fileStream.Write(mc.Content、0、mc.Content.Length); } – mack
'using'文を含めてコードを整理し、文字列リテラル(' @ "C:\ Test.eml" ')で間違いを修正しました。 –
をファイルに保存する前にMimencontentの言語使用のBASE64_DECODEです。
https://github.com/Heartspring/Exchange-Web-Services-for-PHPまたはhttps://github.com/hatsuseno/Exchange-Web-Services-for-PHPを使用するとEWSのAPIとC#を使用して、すべての添付ファイルをダウンロードすることができますライン245または247
に
$newmessage->mc = $messageobj->MimeContent->_;
を追加する必要がある場合。バイトにすべての添付ファイルを変換するコード上方
byte[][] btAttachments = new byte[3][]; //To store 3 attachment
if (item.HasAttachments)
{
EmailMessage message = EmailMessage.Bind(objService, new ItemId(item.Id.UniqueId.ToString()), new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
noOfAttachment = message.Attachments.Count;
// Iterate through the attachments collection and load each attachment.
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the file attachment into memory and print out its file name.
fileAttachment.Load();
//Get the Attachment as bytes
if (i < 3)
{
btAttachments[i] = fileAttachment.Content;
i++;
}
}
// Attachment is an item attachment.
else
{
// Load attachment into memory and write out the subject.
ItemAttachment itemAttachment = attachment as ItemAttachment;
itemAttachment.Load(new PropertySet(EmailMessageSchema.MimeContent));
MimeContent mc = itemAttachment.Item.MimeContent;
if (i < 3)
{
btAttachments[i] = mc.Content;
i++;
}
}
}
}
:以下の例が与えられます。バイトを取得したら、バイトを必要な形式に変換できます。ノーのための場合には、この提案は、@mackでコメントとして投稿が、私はそれが答えとして独自の場所に値すると思われた Write bytes to file http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Save-byte-array-to-file.html
:ファイルにバイトを変換し、以下のリンクをたどるディスクに保存するには 書式設定や読みやすさとコメントの違い以外の理由。
using (FileStream fileStream =
File.Open(@"C:\message.eml", FileMode.Create, FileAccess.Write))
{
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = message.MimeContent;
fileStream.Write(mc.Content, 0, mc.Content.Length);
}
これは、私はあなたがEwsIDにVSTOを経由して、OutlookのEntryIDの(16進数)から予定されている場合はVBSコード
' This is the function that retrieves the message:
function CreaMailMsg(ItemId,ChangeKey)
Dim MailMsg
Dim GetItemSOAP,GetItemResponse,Content
LogFile.WriteLine (Now() & "-" & ":CreaMailMsg:ID:" & ItemId)
GetItemSOAP=ReadTemplate("GetItemMsg.xml")
GetItemSOAP=Replace(GetItemSOAP, "<!--ITEMID-->", ItemId)
GetItemSOAP=Replace(GetItemSOAP, "<!--ITEMCHANGEKEY-->", ChangeKey)
LogFile.WriteLine (Now() & ":GetItemSOAP:" & GetItemSOAP)
set GetItemResponse=SendSOAP(GetItemSOAP,TARGETURL,"",USERNAME,PASSWORD)
' Check we got a Success response
if not IsResponseSuccess(GetItemResponse, "m:GetItemResponseMessage","ResponseClass") then
LogFile.WriteLine (Now() & "-" & ":ERRORE:Fallita GetItemMsg:" & GetItemResponse.xml)
Chiusura 1
end if
' LogFile.WriteLine (Now() & "-" & ":DEBUG:riuscita GetItemMsg:" & GetItemResponse.xml)
Content = GetItemResponse.documentElement.getElementsByTagName("t:MimeContent").Item(0).Text
' LogFile.WriteLine (Now() & ":Contenuto MIME" & Content)
CreaMailMsg = WriteAttach2File(Content,"OriginaryMsg.eml")
' MailMsg.close
CreaMailMsg = true
end function
'###########################################################################
' These are the functions the save the message in .eml format
'###########################################################################
function WriteAttach2File(Content,nomeAttach)
Dim oNode,oXML,Base64Decode
' Read the contents Base64 encoded and Write a file
set oXML=CreateObject("MSXML2.DOMDocument")
set oNode=oXML.CreateElement("base64")
oNode.DataType="bin.base64"
oNode.Text = Content
Base64Decode = Stream_Binary2String(oNode.nodeTypedValue,nomeAttach)
Set oNode = Nothing
Set oXML = Nothing
end function
'###########################################################################
function Stream_Binary2String(binary,nomeAttach)
Const adTypeText = 2
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream=CreateObject("ADODB.Stream")
BinaryStream.Type=adTypeBinary' Binary
BinaryStream.Open
BinaryStream.Write binary
BinaryStream.Position=0
BinaryStream.Type=adTypeText
BinaryStream.CharSet = "us-ascii"
Stream_Binary2String=BinaryStream.ReadText
'msgbox Stream_Binary2String
BinaryStream.SaveToFile ShareName & "\" & nomeAttach,2
Set BinaryStream=Nothing
end function
経由EWSから.emlファイル形式の電子メールメッセージをダウンロードするには、問題を解決する方法でありますここをクリックしてください:http://bernhardelbl.wordpress.com/2013/04/15/converting-entryid-to-ewsid-using-exchange-web-services-ews/
保存しました。私は "データが壊れています。"メッセージ。
message.MimeContentからメッセージのMIMEコンテンツに簡単にアクセスし、メッセージをEMLファイルとして保存できます。最新のOutlook(2013および2016)バージョンでは、EMLファイルを直接開くことができます。
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mimcon = message.MimeContent;
FileStream fStream = new FileStream("c:\test.eml", FileMode.Create);
fStream.Write(mimcon.Content, 0, mimcon.Content.Length);
fStream.Close();
あなたはまだMSG形式に変換する必要がある場合、あなたはいくつかのオプションがあります:
1)MSGファイル形式は文書化されている - それはOLE店(のIStorage)ファイルです。 https://msdn.microsoft.com/en-us/library/cc463912(v=exchg.80).aspx
2)Independentsoft:http://www.independentsoft.de/msg/index.htmlのようなサードパーティのMSGファイルラッパーを使用してください。 Outlookが期待するすべてのプロパティを設定するのは難しいことがあります。
3)を直接Redemptionを使用してMSGにEMLファイルを変換します。
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.CreateMessageFromMsgFile("c:\test.msg")
Msg.Import("c:\test.eml", 1024)
Msg.Save
***に保存**** eml ***は簡単ですが、***に保存してください*** *** ***はサードパーティーです**(_NOTフリー_) – Kiquenet
バイナリレベルでMSGファイルを使用して直接作業することはできますしかし、そうすることで時間やお金を節約できるかどうかという疑問があります。 –
あなたは*** EML ***または***に保存しようとしたしましたMSG ***ファイル。? – Kiquenet