2017-05-04 6 views
0

BLOBがデータを受け取ると、テキスト形式のデータをテキスト形式で送信して、基本的に実行可能ファイルであるazure関数の関数をトリガーしますC++コードでは、終了時に他のブロブに格納されている別のテキストファイルを生成します。プロセスが終了するとazure関数から電子メールを送信します

非常に簡単な操作です。しかし、今は機能がうまくいくたびにメールを受け取っています。私はウェブで検索しましたが、チュートリアルは非常に混乱しています。

私はC++で実行可能ファイルを開発しましたが、私は他の誰かから青空関数を継承しました。私は青空の経験はありません(私は電気工学者ではなくコンピュータサイエンスです)。 azure関数はC#で書かれていますが、私はガイドが必要です。

ありがとうございます!

答えて

4

SendGridの出力バインディングをC#Azure関数に追加することができます。

#r "SendGrid" 
using SendGrid.Helpers.Mail; 

public static void Run(string input, out string yourExistingOutput, out Mail message) 
{ 
    // Do the work you already do 

    message = new Mail 
    {   
     Subject = "Your Subject"   
    }; 

    var personalization = new Personalization(); 
    personalization.AddTo(new Email("[email protected]")); 

    Content content = new Content 
    { 
     Type = "text/plain", 
     Value = "Email Body" 
    }; 
    message.AddContent(content); 
    message.AddPersonalization(personalization); 
} 

についてSendGridSendGrid bindingsを読むような

{ 
    "name": "mail", 
    "type": "sendGrid", 
    "direction": "out", 
    "apiKey" : "MySendGridKey" 
} 

と関数本体:function.jsonに結合すると、このようになります。

0

私はMikhailの解決策が私を解決するのに役立つ同様の問題を抱えていました。私の場合は、静的なRunメソッドを非同期にすることが必要でした。つまり、outパラメータ修飾子を使用できませんでした。私の解決策は、それがタイマートリガーであり、Visual StudioとNuGetパッケージのMicrosoft.Azure.Webjobs.Extensions.SendGrid v2.1.0を使用して実装されたものと少し異なります。

[FunctionName("MyFunction")] 
    public static async Task Run(
     [TimerTrigger("%TimerInterval%")]TimerInfo myTimer, 
     [SendGrid] IAsyncCollector<Mail> messages, 
     TraceWriter log) 
    { 
     log.Info($"C# Timer trigger function started execution at: {DateTime.Now}"); 

     // Do the work you already do... 

     log.Info($"C# Timer trigger function finished execution at: {DateTime.Now}"); 

     var message = new Mail(); 
     message.From = new Email("[email protected]"); 
     var personalization = new Personalization(); 
     personalization.AddTo(new Email("[email protected]")); 
     personalization.Subject = "Azure Function Executed Succesfully"; 
     message.AddPersonalization(personalization); 

     var content = new Content 
     { 
      Type = "text/plain", 
      Value = $"Function ran at {DateTime.Now}", 
     }; 
     message.AddContent(content); 
     await messages.AddAsync(message); 
    } 

このソリューションはHow can I bind output values to my async Azure Function? SendGrid Web API v3 quick start guideへザインRivziの答えを使用していました。

関連する問題