簡體   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