在csom中发送电子邮件附件 [英] Send email attachment in csom

查看:179
本文介绍了在csom中发送电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Folks,


我正在尝试使用CSOM在控制台应用中发送电子邮件附件 


使用显示代码在下面。

 Var emailattach =" http://oneone.abc.com/sites/abc/documents/xyz/123.pdf" ; 

byte [] bytes = System.IO.File.ReadAllBytes(emailattach);

System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
mail.Attachments.Add(new System.Net.Mail.Attachment(stream,emailattach," .Pdf"));

但这里的问题是:它显示异常为  不支持给定路径的格式。


系统发现了System.NotSupportedException

  HResult = -2146233067

 消息=不支持给定路径的格式。

 来源= mscorlib

  StackTrace:

        at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)

        at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions options,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy,
Boolean useLongPath ,布尔检查主机)

        at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options,String msgPath,Boolean bFromProxy,Boolean useLongPath,Boolean checkHost)

        at System.IO.File.InternalReadAllBytes(String path,Boolean checkHost)

       

请帮助您在CSOM中发送电子邮件附件。





问候,


Bharath








记住过去的挑战未来"

解决方案

嗨Bharath,


<请使用WebClient下载文件的字节数组,并在Attachment方法中传递内存流。


以下代码片段供您参考。

 WebClient webClient = new WebClient(); 
webClient.Credentials = new NetworkCredential(" username"," password"," domain");
//下载文件的字节数组
byte [] data = webClient.DownloadData(" http://oneone.abc.com/sites/abc/documents/xyz/123.pdf" );

MemoryStream memoryStreamOfFile = new MemoryStream(data);

mail.Attachments.Add(new System.Net.Mail.Attachment(memoryStreamOfFile," 123.pdf"," application / pdf"));

最好的问候,


Dennis



Hi Folks,

I am trying to send an email attachment in a Console app using CSOM 

Displaying code is used here below.

Var emailattach="http://oneone.abc.com/sites/abc/documents/xyz/123.pdf";

byte[] bytes = System.IO.File.ReadAllBytes(emailattach);

 System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
 mail.Attachments.Add(new System.Net.Mail.Attachment(stream, emailattach, ".Pdf"));

But the problem here is: It is showing exception as The given path's format is not supported.

System.NotSupportedException was caught
  HResult=-2146233067
  Message=The given path's format is not supported.
  Source=mscorlib
  StackTrace:
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
       

Please help in sending email attachment in CSOM.


Regards,

Bharath


Remember Past Challenge Future"

解决方案

Hi Bharath,

Please download the byte array of the file using WebClient, and pass the memory stream in the Attachment method.

The following code snippet for your reference.

WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("username","password","domain");
//Download the byte array of the file
byte[] data = webClient.DownloadData("http://oneone.abc.com/sites/abc/documents/xyz/123.pdf");

MemoryStream memoryStreamOfFile = new MemoryStream(data);

mail.Attachments.Add(new System.Net.Mail.Attachment(memoryStreamOfFile, "123.pdf", "application/pdf"));

Best Regards,

Dennis


这篇关于在csom中发送电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆