1

我可以知道“通过在我的网站中使用 Windows Azure 接收来自客户的电子邮件”吗?

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

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

我可以创建这个功能吗?

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

4

1 回答 1

0

Windows Azure 环境本身当前不提供 SMTP 中继或邮件中继服务。Steve Marx 整理了一个很棒的示例应用程序(可在此处下载),它可以

下列的:

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

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

它使用 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);
于 2013-07-03T06:55:31.407 回答