示例#1
0
        private async Task Run()
        {
            var sender = new HttpV3MessageSender("<YOUR_API_KEY_HERE>");

            // construct and send a message
            Message message = new MessageBuilder()
                              .SetFrom("*****@*****.**")
                              .AddTo("*****@*****.**")
                              .AddCc(new MessageEndPoint("bob", "*****@*****.**"), "*****@*****.**")
                              .SetSubject("test subject")
                              .AddBody("test body")
                              .Build();
            MessageSenderResult result = await sender.Send(message);

            Console.WriteLine(result);

            // same for another message
            message = new MessageBuilder()
                      .SetFrom("*****@*****.**")
                      .AddTo("*****@*****.**")
                      .SetSubject("congrats!")
                      .AddBody(new MessageBody(MessageBodyContentType.Html, "congrats for sending email in HTML!"))
                      .Build();

            result = await sender.Send(message);

            Console.WriteLine(result);
        }
        public static async Task SendBySendGrid(EpostMeddelande meddelande)
        {
            var msg = new MessageBuilder()
                      .SetFrom(meddelande.AvsandareEpost)
                      .AddTo(meddelande.MottagareEpost)
                      .SetSubject(meddelande.Amne)
                      .AddBody(meddelande.Meddelandetext)
                      .Build();

            var sender = new HttpV3MessageSender(_Config.SendGridApiKey);
            var result = await sender.Send(msg);
        }