Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c在Windows Azure上通过电子邮件发送附件#_C#_Email_Azure - Fatal编程技术网

C# 使用c在Windows Azure上通过电子邮件发送附件#

C# 使用c在Windows Azure上通过电子邮件发送附件#,c#,email,azure,C#,Email,Azure,我正在尝试从AZURE发送电子邮件。我成功发送了无附件电子邮件。当我发送带有附件的电子邮件时,我在下载附件时会遇到以下问题 当我打开该附件时,它有0个字节。我在里面找不到任何内容。当我从azure门户下载时,我可以完美地看到内容 对于附件,我上传blob上的PDF文件并下载,然后添加附件。我的代码如下 var account = new CloudStorageAccount(new StorageCredentials("accountName", "keyvalue"), true);

我正在尝试从AZURE发送电子邮件。我成功发送了无附件电子邮件。当我发送带有附件的电子邮件时,我在下载附件时会遇到以下问题

  • 当我打开该附件时,它有0个字节。我在里面找不到任何内容。当我从azure门户下载时,我可以完美地看到内容
对于附件,我上传blob上的PDF文件并下载,然后添加附件。我的代码如下

var account = new CloudStorageAccount(new StorageCredentials("accountName", "keyvalue"), true);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer container =blobClient.GetContainerReference("containername");
CloudBlockBlob blobread = container.GetBlockBlobReference(Session["UploadPDFFile"].ToString());
MemoryStream msRead = new MemoryStream();                                
using (msRead)
{
  msRead.Position = 0;
  blobread.DownloadToStream(msRead);

  objMailMessgae.Attachments.Add(new System.Net.Mail.Attachment(msRead,    Session["UploadPDFFile"].ToString(), "pdf/application"));

   try
   {
     objSmtpClient.Send(objMailMessgae);
   }
   catch (Exception ex) {
            string s = ex.Message;
        }
    }

在将blob的内容读入内存流后,需要将内存流的位置重置为
0
。因此,基本上您的代码是:

var account = new CloudStorageAccount(new StorageCredentials("accountName", "keyvalue"), true);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer container =blobClient.GetContainerReference("containername");
CloudBlockBlob blobread = container.GetBlockBlobReference(Session["UploadPDFFile"].ToString());
MemoryStream msRead = new MemoryStream();                                
using (msRead)
{
  blobread.DownloadToStream(msRead);
  msRead.Position = 0;

  objMailMessgae.Attachments.Add(new System.Net.Mail.Attachment(msRead,    Session["UploadPDFFile"].ToString(), "pdf/application"));

   try
   {
     objSmtpClient.Send(objMailMessgae);
   }
   catch (Exception ex) {
            string s = ex.Message;
        }
    }
试试看。它应该会起作用