【问题标题】:How can I receive Email by using Windows Azure in my Website如何在我的网站中使用 Windows Azure 接收电子邮件
【发布时间】:2013-06-30 17:35:12
【问题描述】:

我能否了解“通过在我的网站中使用 Windows Azure 接收来自客户的电子邮件”?

现在我正在创建我的公司网站。在这个网站上,我将创建“联系我们”页面。 此页面将接受来自我的客户的电子邮件。 但是这封邮件无法通过使用 WIndows Azure 直接到达我的服务器。

我将使用 PHP 语言创建此页面。

我可以创建这个函数吗?

我怎样才能创建这个页面?你知道怎么做吗?

【问题讨论】:

  • 你能更具体地说明你想做什么吗?
  • 我想通过在我的公司网站中传递windows azure来接收电子邮件到我的服务器。我可以创建这个函数吗?如果我可以创建,我想要一个这个函数的例子。

标签: php html azure-storage


【解决方案1】:

Windows Azure 环境本身目前不提供 SMTP 中继或邮件中继服务。 Steve Marx 整理了一个很棒的示例应用程序 (available for download here),它可以完成

以下:

它使用第三方服务 (SendGrid) 从内部发送电子邮件 Windows Azure。

它使用带有输入端点的工作角色来侦听 SMTP 25 端口的流量。

它使用 CDN 端点上的自定义域名来缓存 blob。

这是处理传入电子邮件的代码:

// make a container, with public access to blobs
var id = Guid.NewGuid().ToString().Replace("-", null);
var container = account.CreateCloudBlobClient().GetContainerReference(id);
container.Create();
container.SetPermissions(new BlobContainerPermissions() { PublicAccess=BlobContainerPublicAccessType.Blob });

// parse the message
var msg = new SharpMessage(new MemoryStream(Encoding.ASCII.GetBytes(message.Data)),
    SharpDecodeOptions.AllowAttachments | SharpDecodeOptions.AllowHtml | SharpDecodeOptions.DecodeTnef);

// create a permalink-style name for the blob
var permalink = Regex.Replace(Regex.Replace(msg.Subject.ToLower(), @"[^a-z0-9]", "-"), "--+", "-").Trim('-');
if (string.IsNullOrEmpty(permalink))
{
    // in case there's no subject
    permalink = "message";
}
var bodyBlob = container.GetBlobReference(permalink);
// set the CDN to cache the object for 2 hours
bodyBlob.Properties.CacheControl = "max-age=7200";

// replaces references to attachments with the URL of where we'll put them
msg.SetUrlBase(Utility.GetCdnUrlForUri(bodyBlob.Uri) + "/[Name]");

// save each attachment in a blob, setting the appropriate content type
foreach (SharpAttachment attachment in msg.Attachments)
{
    var blob = container.GetBlobReference(permalink + "/" + attachment.Name);
    blob.Properties.ContentType = attachment.MimeTopLevelMediaType + "/" + attachment.MimeMediaSubType;
    blob.Properties.CacheControl = "max-age=7200";
    attachment.Stream.Position = 0;
    blob.UploadFromStream(attachment.Stream);
}
// add the footer and save the body to the blob
SaveBody(msg, bodyBlob, message, container, permalink);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2020-11-29
    • 2019-08-11
    • 2014-06-16
    相关资源
    最近更新 更多