當前位置: 首頁>>代碼示例>>C#>>正文


C# SendGrid.SendGridMessage類代碼示例

本文整理匯總了C#中SendGrid.SendGridMessage的典型用法代碼示例。如果您正苦於以下問題:C# SendGridMessage類的具體用法?C# SendGridMessage怎麽用?C# SendGridMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SendGridMessage類屬於SendGrid命名空間,在下文中一共展示了SendGridMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: configSendGridasync

        // Use NuGet to install SendGrid (Basic C# client lib) 
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress("[email protected]", "Francisco Paz");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            // Create network credentials to access your SendGrid account
            var username = "";
            var pswd = "";

            var credentials = new NetworkCredential(username, pswd);
            
            //var credentials = new NetworkCredential(ConfigurationManager.AppSettings["emailService:Account"],
            //                                        ConfigurationManager.AppSettings["emailService:Password"]);

            // Create a Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
開發者ID:FranPaz,項目名稱:VLaboralApi,代碼行數:34,代碼來源:EmailService.cs

示例2: configSendGridasync

        private Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                                "[email protected]", "Joe S.");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                       ConfigurationManager.AppSettings["mailAccount"],
                       ConfigurationManager.AppSettings["mailPassword"]
                       );

            // Create a Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            if (transportWeb != null)
            {
                return transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                return Task.FromResult(0);
            }
        }
開發者ID:YangTianb,項目名稱:asp.net,代碼行數:28,代碼來源:EmailService.cs

示例3: AddedParticipantsAsync

        private async Task AddedParticipantsAsync(List<string> participants, RateSystem rateSystem)
        {
            var myMessage = new SendGridMessage();

            foreach (var participant in participants)
            {
                myMessage.AddTo(participant);
                myMessage.From = new System.Net.Mail.MailAddress("[email protected]", "Система за гласуване.");
                myMessage.Subject = "Начало на система.";
                myMessage.Html = "Здравейте! Вие бяхте добавен към "+ rateSystem.RateSystemName + " система, която започва на "+ rateSystem.StarDateTime + " и свършва на " + rateSystem.EndDateTime + ". Моля отделете време и гласувайте. " +
                    "<a href =\"http://votesystem.apphb.com\">Вход към сайта.</a>";

                var transportWeb = new Web("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");

                try
                {
                    if (transportWeb != null)
                    {
                        await transportWeb.DeliverAsync(myMessage);
                    }
                    else
                    {
                        await Task.FromResult(0);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
開發者ID:chunk1ty,項目名稱:VoteSystem,代碼行數:31,代碼來源:EmailService.cs

示例4: SendMailAsync

        public async Task<bool> SendMailAsync(MailMessage mm, bool suppressExceptions=true)
        {
            try
            {
                string userName = _configurationService.SendGridUsername;
                string password = _configurationService.SendGridPassword;

                var message = new SendGridMessage();

                message.From = new MailAddress(mm.From);
                message.AddTo(mm.To);
                message.Subject = mm.Subject;
                message.Text = mm.Body;

                var credentials = new NetworkCredential(userName, password);
                var transportWeb = new Web(credentials);
                await transportWeb.DeliverAsync(message).ConfigureAwait(false);

                return true;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                if (!suppressExceptions)
                    throw;
            }

            return false;
        }
開發者ID:transformersprimeabcxyz,項目名稱:ResourceFirstTranslations,代碼行數:30,代碼來源:SendGridMailService.cs

示例5: FeedbackEmailAsync

        private async Task FeedbackEmailAsync(FeedbackViewModel message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo("[email protected]");
            myMessage.From = new System.Net.Mail.MailAddress(message.Email, message.Name);
            myMessage.Subject = message.Subject;
            myMessage.Html = message.Message;

            var transportWeb = new Web("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");

            try
            {
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
開發者ID:chunk1ty,項目名稱:VoteSystem,代碼行數:27,代碼來源:EmailService.cs

示例6: ConfigSendGridasync

        private async Task ConfigSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress("[email protected]", "Система за гласуване.");
            myMessage.Subject = message.Subject;
            myMessage.Html = message.Body;

            var transportWeb = new Web("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");
            try
            {
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
開發者ID:chunk1ty,項目名稱:VoteSystem,代碼行數:26,代碼來源:EmailService.cs

示例7: CreateMimeMessage

        public void CreateMimeMessage()
        {
            var message = new SendGridMessage();
            var attachment = Path.GetTempFileName();
            var text = "this is a test";
            var html = "<b>This<\b> is a better test";
            var headers = new KeyValuePair<String, String>("custom", "header");
            message.AddAttachment(attachment);
            message.Text = text;
            message.Html = html;
            message.AddTo("[email protected]");
            message.From = new MailAddress("[email protected]");
            message.AddHeaders(new Dictionary<string, string> {{headers.Key, headers.Value}});
            message.EnableGravatar();

            var mime = message.CreateMimeMessage();

            var sr = new StreamReader(mime.AlternateViews[0].ContentStream);
            var result = sr.ReadToEnd();
            Assert.AreEqual(text, result);

            sr = new StreamReader(mime.AlternateViews[1].ContentStream);
            result = sr.ReadToEnd();
            Assert.AreEqual(html, result);

            result = mime.Headers.Get(headers.Key);
            Assert.AreEqual(headers.Value, result);

            result = mime.Headers.Get("X-Smtpapi");
            var expected = "{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}";
            Assert.AreEqual(expected, result);

            result = mime.Attachments[0].Name;
            Assert.AreEqual(Path.GetFileName(attachment), result);
        }
開發者ID:npadmanabhan,項目名稱:sendgrid-csharp,代碼行數:35,代碼來源:TestSendgrid.cs

示例8: Post

        // POST: api/RequestData
        public HttpResponseMessage Post([FromBody]RequestData value)
        {
            try
            {
                // Create the email object first, then add the properties.
                SendGridMessage myMessage = new SendGridMessage();
                myMessage.AddTo("[email protected]");
                myMessage.From = new MailAddress("[email protected]");
                myMessage.Subject = string.Format("Message from DRB Technology");
                myMessage.Text = string.Format("From: {0} {1} \n Message: {2}", value.email, value.yourName, value.yourRequest);

                // Create credentials, specifying your user name and password.
                //TODO: Set credentials
                var credentials = new NetworkCredential("", "");

                // Create an Web transport for sending email, using credentials...
                var transportWeb = new Web(credentials);

                // ...OR create a Web transport, using API Key (preferred)
                //var transportWeb = new Web("This string is an API key");

                // Send the email.
                transportWeb.DeliverAsync(myMessage);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException);
            }

            return Request.CreateResponse(HttpStatusCode.OK, "Thank you for your request. We aim to respond within 24 hours.");
        }
開發者ID:BourkeDavid,項目名稱:drbtechnology,代碼行數:32,代碼來源:RequestDataController.cs

示例9: configSendGridasync

        // Use NuGet to install SendGrid (Basic C# client lib) 
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                                "[email protected]", "LaFactureria");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                       ConfigurationManager.AppSettings["mailAccount"],
                       ConfigurationManager.AppSettings["mailPassword"]
                       );

            // Create a Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                Trace.TraceError("Fallo al crear el transporte Web y no se fue posible enviar el correo.");
                await Task.FromResult(0);
            }
        }
開發者ID:Jaer86,項目名稱:RedNuc,代碼行數:30,代碼來源:ServicioDeCorreo.cs

示例10: EmailReceipt

        public void EmailReceipt(byte[] file, string fileName, OrderViewModel order)
        {
            // Set our SendGrid API User and Key values for authenticating our transport.
            var sendGridApiKey = "";
            var sendGridApiUser = "";

            // Create the email object first, and then add the properties.
            var myMessage = new SendGridMessage();

            // Add the message properties.
            myMessage.From = new MailAddress("[email protected]");

            // Add customer's email addresses to the To field.
            myMessage.AddTo(order.Email);

            myMessage.Subject = "Contoso Sports League order received";

            // Add the HTML and Text bodies.
            myMessage.Html = "";
            myMessage.Text = "";

            // Add our generated PDF receipt as an attachment.
            using (var stream = new MemoryStream(file))
            {
                myMessage.AddAttachment(stream, fileName);
            }

            var credentials = new NetworkCredential(sendGridApiUser, sendGridApiKey);
            // Create a Web transport using our SendGrid API user and key.
            var transportWeb = new Web(credentials);

            // Send the email.
            transportWeb.DeliverAsync(myMessage);
        }
開發者ID:ryankmcintyre,項目名稱:P20SummerCamp,代碼行數:34,代碼來源:EmailMethods.cs

示例11: Process

        public async Task<ProviderProcessResult> Process(Message message)
        {
            try
            {
                var msg = new SendGridMessage();
                msg.AddTo(message.To);
                msg.From = new MailAddress(message.Application.EmailFromAddress, message.Application.EmailFromFullName);
                msg.Subject = message.Subject;
                msg.Html = message.Content;

                var transportWeb = new Web(ConfigurationManager.AppSettings["SendGridSecretKey"]);

                await transportWeb.DeliverAsync(msg);

                return new ProviderProcessResult { IsSuccess = true };
            }
            catch (Exceptions.InvalidApiRequestException ex)
            {
                return new ProviderProcessResult { IsSuccess = false, ErrorMessage = String.Join(",", ex.Errors), ErrorDetails = ex.ToString() };
            }
            catch (Exception ex)
            {
                return new ProviderProcessResult { IsSuccess = false, ErrorMessage = ex.Message, ErrorDetails = ex.ToString() };
            }
        }
開發者ID:sal0,項目名稱:notifications,代碼行數:25,代碼來源:SendGridProviderManager.cs

示例12: SendGridAsync

        private async Task SendGridAsync(IdentityMessage message)
        {
            var sec = (ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection);

            if (sec != null)
            {
                var displayName = sec.From;
                var fromEmailAddress = sec.Network.UserName;
                var passwordEmail = sec.Network.Password;

                var sendMessage = new SendGridMessage()
                {
                    From = new MailAddress(fromEmailAddress, displayName),
                    Subject = message.Subject,
                    Text = message.Body,
                    Html = message.Body
                };
                sendMessage.AddTo(message.Destination);

                var credentials = new NetworkCredential(fromEmailAddress, passwordEmail);
                var transportWeb = new Web(credentials);
                if (transportWeb != null)
                {
                    await transportWeb.DeliverAsync(sendMessage);
                }
                else
                {
                    await Task.FromResult(0);
                }
            }
            else
            {
                await Task.FromResult(0);
            }
        }
開發者ID:ranieresilva,項目名稱:ingresso,代碼行數:35,代碼來源:EmailService.cs

示例13: Enviar

        public void Enviar(string nome, string email, string assunto, string mensagem)
        {
            var myMessage = new SendGridMessage();

            myMessage.From = new MailAddress(email, nome);
            myMessage.AddTo("[email protected]");
            myMessage.Subject = assunto;
            myMessage.Text = mensagem;

            var username = "[email protected]";
            var pswd = "20LTaus55pBSA3m";
            /* Alternatively, you may store these credentials via your Azure portal
               by clicking CONFIGURE and adding the key/value pairs under "app settings".
               Then, you may access them as follows:
               var username = System.Environment.GetEnvironmentVariable("SENDGRID_USER");
               var pswd = System.Environment.GetEnvironmentVariable("SENDGRID_PASS");
               assuming you named your keys SENDGRID_USER and SENDGRID_PASS */

            var credentials = new NetworkCredential(username, pswd);
            var transportWeb = new Web(credentials);

            // Send the email.
            // You can also use the **DeliverAsync** method, which returns an awaitable task.
            transportWeb.DeliverAsync(myMessage);
        }
開發者ID:BrenoSarkis,項目名稱:Blog,代碼行數:25,代碼來源:EnviadorDeEmail.cs

示例14: ConfigSendGridasync

        // Implementação do SendGrid
        private Task ConfigSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new MailAddress("[email protected]", "Admin do Portal");
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["mailAccount"], ConfigurationManager.AppSettings["mailPassword"]);

            // Criar um transport web para envio de e-mail
            var transportWeb = new Web(credentials);

            // Enviar o e-mail
            if (transportWeb != null)
            {
                var x = transportWeb.DeliverAsync(myMessage);
                return x;
            }
            else
            {
                return Task.FromResult(0);
            }
        }
開發者ID:luancarloswd,項目名稱:CoachingPlan,代碼行數:26,代碼來源:EmailService.cs

示例15: configSendGridasync

        // Use NuGet to install SendGrid (Basic C# client lib) 
        private async Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();

            myMessage.AddTo(message.Destination);
            myMessage.From = new MailAddress(
                AppSettingsService.NoReplyEmail,
                AppSettingsService.NoReplyFullname);
            myMessage.Subject = message.Subject;
            myMessage.Text = message.Body;
            myMessage.Html = message.Body;

            var credentials = new NetworkCredential(
                AppSettingsService.EmailServiceAccount,
                AppSettingsService.EmailServicePassword);

            // Create a Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            if (transportWeb != null)
            {
                await transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                //Trace.TraceError("Failed to create Web transport.");
                await Task.FromResult(0);
            }
        }
開發者ID:phmatray,項目名稱:Camarilla,代碼行數:31,代碼來源:EmailService.cs


注:本文中的SendGrid.SendGridMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。