コード例 #1
0
        public Task<IHttpActionResult> SendMail(EmailModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var smtp = new System.Net.Mail.SmtpClient();
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential("*****@*****.**", "Abc@123456");
                    smtp.Timeout = 20000;
                }
                smtp.Send(configuration.FromAddress, toAddress, configuration.Subject, body);
                return true;
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                return false;
            }
        }
コード例 #2
0
ファイル: LotteryController.cs プロジェクト: vanan08/ADSoft
        public async Task<IHttpActionResult> SendMail(EmailModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var smtp = new System.Net.Mail.SmtpClient();
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential("*****@*****.**", "Abc@123456");
                    smtp.Timeout = 20000;
                }
                smtp.Send("*****@*****.**", model.ToAddress, model.Subject, model.Body);
                return Ok("Ok");
            }
            catch (Exception ex)
            {
                return Ok(ex.Message);
            }
        }