Example #1
0
        public void SendEmail(string toEmail, string title, string content, string userAddress = null, string password = null)
        {
            if (userAddress == null)
            {
                userAddress = _appSettings.Value.Email.UserAddress;
                password    = _appSettings.Value.Email.UserPassword;
            }
            else
            {
                var dic = new Dictionary <string, string>();
                dic.Add(_appSettings.Value.MainEmail.UserAddress, _appSettings.Value.MainEmail.UserPassword);
                dic.Add(_appSettings.Value.Email.UserAddress, _appSettings.Value.Email.UserPassword);
                foreach (var item in dic)
                {
                    if (item.Key == userAddress)
                    {
                        userAddress = item.Key;
                        password    = item.Value;
                    }
                }
            }
            var mailer = new MailInfo()
            {
                Port        = 465,
                UseSsl      = true,
                Host        = _appSettings.Value.Email.Host,
                UserName    = "******" + _appSettings.Value.Webs[0].Url,
                UserAddress = userAddress,
                Password    = password,
                Content     = content,
                Subject     = title
            };

            mailer.Reset();
            mailer.AddToAddress(toEmail);
            _ = MailHelper.SendAsync(mailer);
        }