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)?它有发送电子邮件日志吗? –
不,不显示数据。 –