当您以 *.msg 文件格式保存电子邮件并将文件上传到 SharePoint Online 时,它不会在 Outlook Web App (OWA) 中打开,因为 OWA 不理解 *.msg 文件格式(丰富的文件格式)。您可以下载该文件并使用您的 Outlook 客户端打开。
如果您想创建一个应用程序来实现这一点。在 c# 中,您可以通过以下步骤使用 SharePoint Client dll:
1.通过用户名和密码创建的凭据对象向SharePoint发出请求:
ClientContext context = new ClientContext(SiteUrl);
context.Credentials = new SharePointOnlineCredentials(UserName, Password);
2.提供文件url从.msg文件中读取数据:
public Stream GetFile()
{
using (ClientContext clientContext = GetContextObject())
{
Web web = clientContext.Web;
clientContext.Load(web, website => website.ServerRelativeUrl);
clientContext.ExecuteQuery();
Regex regex = new Regex(SiteUrl, RegexOptions.IgnoreCase);
string strSiteRelavtiveURL = regex.Replace(FileUrl, string.Empty);
string strServerRelativeURL = CombineUrl(web.ServerRelativeUrl, strSiteRelavtiveURL);
Microsoft.SharePoint.Client.File oFile = web.GetFileByServerRelativeUrl(strServerRelativeURL);
clientContext.Load(oFile);
ClientResult<Stream> stream = oFile.OpenBinaryStream();
clientContext.ExecuteQuery();
return this.ReadFully(stream.Value);
}
}
3。您可以下载带有 FileStream 对象的 .msg 文件(点击here 下载整个演示)。之后,您可以use c# to read information from the file 然后通过 System.Net.Mail.MailMessage 发送电子邮件:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
SmtpClient SmtpServer = new SmtpClient("servername");
mail.From = new MailAddress(strFromAddress);
mail.To.Add(strToAddress);
mail.Subject = strSubject;
mail.Body = strMessage;
SmtpServer.Send(mail);