email - 从辅助角色 (Azure) 发送带有 C# 附件的电子邮件

标签 email azure send role worker

我正在尝试从辅助角色(Azure)发送一封带有附件(来自blob存储)的电子邮件(在c#中)。 我可以发送电子邮件,但附件(word 文档)为空。 从辅助角色调用以下函数。

    public void sendMail(string blobName)
    { 
            InitStorage();//Initialize the storage
            var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            container = blobStorage.GetContainerReference("Container Name");
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            if (File.Exists("demo.doc"))
                File.Delete("demo.doc");

            FileStream fs = new FileStream("demo.doc", FileMode.OpenOrCreate);
            blob.DownloadToStream(fs);                
            Attachment attach = new Attachment(fs,"Report.doc");
            System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d184a2b4a391b9bea5bcb0b8bdffb2bebc" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="722701170032151f131b1e5c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>");
            Email.Subject = "Text fax send via email";
            Email.Subject = "Subject Of email";
            Email.Attachments.Add(attach);
            Email.Body = "Body of email";
            System.Net.Mail.SmtpClient client = new SmtpClient("smtp.live.com", 25);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="396c4a5c4b7951564d54585055175a5654" rel="noreferrer noopener nofollow">[email protected]</a>", Password);
            client.Send(Email);
            fs.Flush();
            fs.Close();
            Email.Dispose();                       
    }

请告诉我哪里做错了?

最佳答案

在附加创建 Attachment 对象之前,我会尝试执行 fs.Position = 0; 操作。

可能发生的情况是,它试图从流中的当前位置读取,而该流位于末尾,因此它什么也没读取。

关于email - 从辅助角色 (Azure) 发送带有 C# 附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4637822/

相关文章:

email - 电子邮件 header 可以使用与电子邮件正文不同的字符编码吗?

azure - Terraform 在资源 block 和资源 block 内启用或禁用参数?

android - 超时异常(从 Android 向 PHP 页面发送数据)

sms - 如何批量重发失败短信

java - MimeMessage 中的智能引号未在 Outlook 中正确显示

c# - 来自 asp.net c# 程序的电子邮件非常慢

azure - 如何使用 NextJS API 将图像上传到 Azure Blob 存储?

git - 我的 Azure 更改未发布到我的网站上

Android 模拟/发送 ACTION_MEDIA_BUTTON Intent

python - 换行符出现在屏幕上但不出现在电子邮件中