繁体   English   中英

通过mailgun接收电子邮件

[英]Receiving email through mailgun

我是使用mailgun的新手。 但我的任务是创建一个C#MVC控制器,它将接收mailgun转发的电子邮件。 我在mailgun发布的文档中看到了一个示例代码来执行此操作,但它使用的是Django,我对此并不十分熟悉。 以下是用Django编写的示例代码:

def on_incoming_message(request):
 if request.method == 'POST':
     sender    = request.POST.get('sender')
     recipient = request.POST.get('recipient')
     subject   = request.POST.get('subject', '')

     body_plain = request.POST.get('body-plain', '')
     body_without_quotes = request.POST.get('stripped-text', '')
     # note: other MIME headers are also posted here...

     # attachments:
     for key in request.FILES:
         file = request.FILES[key]
         # do something with the file

 # Returned text is ignored but HTTP status code matters:
 # Mailgun wants to see 2xx, otherwise it will make another attempt in 5 minutes
 return HttpResponse('OK')

我现在的问题是,我如何在C#中转换它? 一个示例代码绝对是惊人的。 我在这里先向您的帮助表示感谢。 对不起,如果你发现这个问题很愚蠢。

你需要做的是从mailgun接收post请求,然后将它分成它的各个部分,这就是django示例在上面做的。

这是如何收到http帖子的示例。

public void ProcessRequest(HttpContext context)
{
    var value1 = context.Request["param1"];
    var value2 = context.Request["param2"];
    ...
}

它使用的是一个C#库,可以很容易地读取POST的内容。

看看这个更详细的信息:

http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.90).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM