当前位置: 首页>>代码示例>>C#>>正文


C# SendGridMessage.AddTo方法代码示例

本文整理汇总了C#中SendGrid.SendGridMessage.AddTo方法的典型用法代码示例。如果您正苦于以下问题:C# SendGridMessage.AddTo方法的具体用法?C# SendGridMessage.AddTo怎么用?C# SendGridMessage.AddTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SendGrid.SendGridMessage的用法示例。


在下文中一共展示了SendGridMessage.AddTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMailNotification

        public async  void SendMailNotification(string sharePointAppUrl, string name, string useremail = null)
        {
                string description = $"Sharepoint site '{name}' created.";
                var urlValue = "<a href=" + name + ">" + sharePointAppUrl + "</a>";

                object[] parameters = { description , urlValue };
                var msgBody = GetMailMessage(parameters);

                var mailMessage = new SendGridMessage();

                var mailFrom = WebConfigurationManager.AppSettings["MailFrom"];
                var maintenanceEmailAddress = WebConfigurationManager.AppSettings["MaintenanceEmailAddress"];
                var mailUserName = WebConfigurationManager.AppSettings["MailUserID"];
                var mailPassword = WebConfigurationManager.AppSettings["MailPassword"];

                mailMessage.From = new MailAddress(mailFrom);
                var recipients = new List<string> {maintenanceEmailAddress};

                if (useremail != null)
                {
                    recipients.Add(useremail);
                }

                recipients.Add(mailFrom);
                mailMessage.AddTo(recipients);

                mailMessage.Subject =  description; 
                mailMessage.Html = msgBody;

                var credentials = new NetworkCredential(mailUserName, mailPassword);
                var transportWeb = new Web(credentials);
                await transportWeb.DeliverAsync(mailMessage);
            

        }
开发者ID:sogeti,项目名称:Site-provisioning,代码行数:35,代码来源:NotificationMail.cs

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: configSendGridasync

        private Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                                "[email protected]oso.com", "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

示例13: 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

示例14: SendAdminEmail

        public void SendAdminEmail(Usuario usuario)
        {
            // Create the email object first, then add the properties.
            var myMessage = new SendGridMessage();

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

            // Add multiple addresses to the To field.
            List<string> recipients = new List<string>
            {
                @"[email protected]"
            };

            myMessage.AddTo(recipients);

            myMessage.Subject = "Novo Usuário!";

            myMessage.Html += string.Format(@"<table>
            <tr><th>Nome</th><th>Sobrenome</th><th>Email</th>
            <th>Telefone</th><th>Endereço</th><th>Cidade</th>
            <th>Estado</th><th>País</th><th>Programas</th>
            <th>Profile</th><th>Sobre</th></tr>
            <tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td>
            <td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td>
            <td>{9}</td><td>{10}</td></tr></table>", usuario.FirstName, usuario.LastName, usuario.Email,
            usuario.PhoneNumber, usuario.Address, usuario.City,
            usuario.State, usuario.Country, string.Join(",", usuario.Programs.ToArray()),
            usuario.CurrentProfile, usuario.About);

            this.SendEmail(myMessage);
        }
开发者ID:ericpsantos,项目名称:Joule,代码行数:32,代码来源:SendGridService.cs

示例15: enviarAlerta

        /*
        static string smtpAddress = "smtp.gmail.com";
        static int portNumber = 587;
        static bool enableSSL = true;
        static string emailFrom = "[email protected]";
        static string password = "europe2089";
        //string emailTo = "[email protected]";
        static string subject = "";
        static string body = "";
        static string org;
        //*/
        /*
        public static void enviarAlerta(string emailTo, string subject,string body)
        {
            try
            {                

                using (MailMessage mail = new MailMessage())
                {
                    mail.From = new MailAddress(emailFrom);
                    mail.To.Add(emailTo);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = true;
                    // Can set to false, if you are sending pure text.

                    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                    {
                        smtp.Credentials = new NetworkCredential(emailFrom, password);
                        smtp.EnableSsl = enableSSL;
                        smtp.Send(mail);
                    }
                }
            }
            catch
            {
                
            }
        }
        //*/

        public static void enviarAlerta(List<string> emailTo, string subject, string body) 
        {
            // Add multiple addresses to the To field.
            List<String> recipients = emailTo;

            var username = System.Environment.GetEnvironmentVariable("SENDGRID_USERNAME");
            var pswd = System.Environment.GetEnvironmentVariable("SENDGRID_PASSWORD");

            // Create the email object first, then add the properties.
            SendGridMessage myMessage = new SendGridMessage();
            myMessage.AddTo(recipients);
            myMessage.From = new MailAddress("[email protected]", "Sistema de avisos Renta-Maq");
            myMessage.Subject = subject;
            myMessage.Html= body;

            // Create credentials, specifying your user name and password.
            var credentials = new NetworkCredential(username, pswd);

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

            // Send the email, which returns an awaitable task.
            transportWeb.DeliverAsync(myMessage);

            // If developing a Console Application, use the following
            // transportWeb.DeliverAsync(mail).Wait();
        }
开发者ID:gpuellestorres,项目名称:RentaMaq,代码行数:68,代码来源:envioCorreos.cs


注:本文中的SendGrid.SendGridMessage.AddTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。