0
我有一個Kendo上傳將文件上傳到Azure blob。我想發送一封附有Kendo上傳文件的附件併發送電子郵件。 這裏是我的嘗試:SendGridMessage帶附件的電子郵件
System.Web.HttpPostedFileBase doc;
string filepath;
string uniqueBlobName;
public ActionResult UploadRegistry()
{
doc = Request.Files["Registry"];
var inputstream = doc.InputStream;
var filename = doc.FileName;
var doctype = doc.ContentType;
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorageConnection"].ConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("registrynumber");
container.CreateIfNotExists();
var permission = container.GetPermissions();
uniqueBlobName = string.Format("Document/{0}", filename);
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = doctype;
blob.UploadFromStream(inputstream);
filepath = blob.Uri.AbsoluteUri;
TempData["Document"] = doc.FileName;
TempData["Document1"] = filepath;
string address ="[email protected]";
var credentials = new NetworkCredential("username", "password");
var myMessage = new SendGridMessage();
// Add the message properties.
myMessage.From = new MailAddress("[email protected]", "Test");
myMessage.AddAttachment(filepath);
myMessage.AddTo(address);
myMessage.Subject = "Document";
var transportWeb = new Web(credentials);
var x = transportWeb.DeliverAsync(myMessage);
return Json(new { success = true });
}
後來,我得到一個錯誤,該文件路徑是無效的。我能做什麼?
事實上,沒有異常拋出,但仍然沒有郵件... –
你有沒有檢查這個[URL](https://app.sendgrid.com/ email_activity)?它有發送電子郵件日誌嗎? –
不,不顯示數據。 –