///// <summary>
        ///// QQ邮件服务器
        ///// </summary>
        ///// <param name="email"></param>
        ///// <returns></returns>
        //public async Task<IActionResult> Index([FromServices]IFluentEmail email)
        //{
        //    var model = new
        //    {
        //        Name = "peter"
        //    };

        //    await email
        //        .SetFrom("*****@*****.**")
        //        .To("*****@*****.**")
        //        .Subject("test email subject")
        //        .UsingTemplate(@"hi @Model.Name this is a razor template @(5 + 5)!", model)
        //        .SendAsync();

        //    return View();
        //}



        /// <summary>
        ///Aliyun
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task <IActionResult> Index([FromServices] IFluentEmail email)
        {
            IClientProfile        profile = DefaultProfile.GetProfile("cn-hangzhou", "LTAIp6xGrmeOdHig", "dkVvKPhMk0ZQOuS86IaMbR4jUuqvCC");
            IAcsClient            client  = new DefaultAcsClient(profile);
            SingleSendMailRequest request = new SingleSendMailRequest();

            try
            {
                request.AccountName    = "控制台创建的发信地址";
                request.FromAlias      = "peter";
                request.AddressType    = 1;
                request.TagName        = "控制台创建的标签";
                request.ReplyToAddress = true;
                request.ToAddress      = "目标地址";
                request.Subject        = "邮件主题";
                request.HtmlBody       = "邮件正文";
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
            }
            catch (ServerException e)
            {
                View(e.StackTrace);
            }
            catch (ClientException e)
            {
                View(e.StackTrace);
            }

            return(View());
        }
Exemplo n.º 2
0
    public bool sendMail(string emailaddress, string code)
    {
        SingleSendMailRequest request = new SingleSendMailRequest();

        try
        {
            request.AccountName    = myemail;
            request.FromAlias      = "campustalk官方团队";
            request.AddressType    = 1;
            request.TagName        = "Regesiter";
            request.ReplyToAddress = true;
            request.ToAddress      = emailaddress;
            request.Subject        = "[campustalk]验证码消息";
            request.HtmlBody       = "欢迎注册campustalk,您的验证码为:" + code + "。验证码有效期为:" + GlobalVar.CODE_VAL_TIME + "分钟";
            SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
        }
        catch (ServerException e)
        {
            return(false);
        }
        catch (ClientException e)
        {
            return(false);
        }
        return(true);
    }
Exemplo n.º 3
0
        public static bool SendEmail(string name, string code, string email)
        {
            string HtmlBody = string.Format("<p>Logo</p><hr/><p>Hi,{0}<br/></p><p><br/></p><p>感谢你注册<a href='http://www.dayuweb.cn' target='_self'title='Dayuweb.cn'>www.dayuweb.cn</a></p><p>您的激活码是:</p><p style='text-align: center;'><span style='font-size: 24px;color:#938953'><strong>{1}</strong></span><br/></p><p style='text-align: left;'><span style='font-size:16px;color:#000000'>该激活码有效期为2天,请你及时激活,妥善保管激活码!请勿泄露</span></p><p style='text-align: left;'><span style='font-size:16px;color:#000000'><br/></span></p><p style='text-align: left;'><span style='font-size:16px;color:#000000'>-大鱼互联团队</span></p><hr/><p style='text-align: left;'><span style='font-size:12px;color:#3f3f3f'>如果你没有注册过dayuweb.cn,请忽略&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 获取帮助:https://dayuweb.cn/help</span> </p><p style='text-align: left;'><span style='font-size: 24px;color:#938953'><span style='color: rgb(255, 255, 255);'><span style='font-size: 16px;'>gai</span></span><br/></span></p>", name, code);

            bool                  isSuccess = false;
            IClientProfile        profile   = DefaultProfile.GetProfile("cn-hangzhou", "LTAIHWbwAjMRMrnR", "31nlB0FinmBhwMbVYz4UED8PZx6NSf");
            IAcsClient            client    = new DefaultAcsClient(profile);
            SingleSendMailRequest request   = new SingleSendMailRequest();

            try
            {
                request.AccountName    = "*****@*****.**";
                request.FromAlias      = "大鱼互联";
                request.AddressType    = 1;
                request.TagName        = "emailCode";
                request.ReplyToAddress = true;
                request.ToAddress      = email;
                request.Subject        = "账户激活码";
                request.HtmlBody       = HtmlBody;
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                isSuccess = true;
            }
            catch
            {
                isSuccess = false;
            }
            return(isSuccess);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过阿里云发送邮件 2018-4-8
        /// </summary>
        /// <param name="subject">主题</param>
        /// <param name="body">正文</param>
        /// <param name="toAddress">接收方地址</param>
        /// <param name="fromAddress">发送方地址:与阿里云邮件管理后台配置信息保持一致</param>
        /// <param name="fromName">发送方昵称</param>
        /// 阿里云文档地址:https://help.aliyun.com/document_detail/29461.html?spm=a2c4g.11186623.6.584.3KIzpj
        public bool SendEmailByAliYun(string subject, string body, string toAddress, string fromAddress, string fromName)
        {
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou",
                                                               _configuration.GetSection("OSS")["AccessKeyId"],
                                                               _configuration.GetSection("OSS")["AccessKeySecret"]);
            IAcsClient            client  = new DefaultAcsClient(profile);
            SingleSendMailRequest request = new SingleSendMailRequest();

            request.AccountName = fromAddress; //控制台创建的发信地址
            request.FromAlias   = fromName;    //发信人昵称
            request.AddressType = 1;
            //request.TagName = "控制台创建的标签";
            request.ReplyToAddress = false;
            request.ToAddress      = toAddress; //目标地址
            request.Subject        = subject;   //邮件主题
            request.HtmlBody       = body;      //邮件正文
            try
            {
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
            }
            catch (Exception ex)
            {
                var messgae = ex.Message;
                return(false);
            }
            //if (httpResponse.HttpResponse.Status != 200)
            //{
            //    return false;
            //}
            return(true);
        }
Exemplo n.º 5
0
        public static bool SendMail()
        {
            IClientProfile        profile = DefaultProfile.GetProfile("cn-hangzhou", "LTAIaf00roGRwfnJ", "GDPQuJT9jUAMieIBIT0U110GDLb5xg");
            IAcsClient            client  = new DefaultAcsClient(profile);
            SingleSendMailRequest request = new SingleSendMailRequest();

            try
            {
                request.AccountName    = "*****@*****.**";
                request.FromAlias      = "简悦简历";
                request.AddressType    = 1;
                request.TagName        = "jianyue";
                request.ReplyToAddress = true;
                request.ToAddress      = "*****@*****.**";
                request.Subject        = "简悦简历";
                request.HtmlBody       = "这是一封简悦简历的测试邮件!";
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                return(true);
            }
            catch (ServerException e)
            {
                //e.printStackTrace();
                return(false);
            }
            catch (ClientException e)
            {
                //e.printStackTrace();
                return(false);
            }
        }
Exemplo n.º 6
0
 public async Task Send(MailModel message)
 {
     await Task.Run(() => {
         IClientProfile profile        = DefaultProfile.GetProfile(_appConfig.Aliyun.RegionId, _appConfig.Aliyun.AccessKeyId, _appConfig.Aliyun.AccessKeySecret);
         IAcsClient client             = new DefaultAcsClient(profile);
         SingleSendMailRequest request = new SingleSendMailRequest();
         try
         {
             request.AccountName    = _appConfig.Email.AccountName;
             request.FromAlias      = _appConfig.Email.FromAlias;
             request.AddressType    = 1;
             request.ReplyToAddress = true;
             request.ToAddress      = message.Address;
             request.Subject        = message.Subject;
             request.HtmlBody       = "1111111111111";
             SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
         }
         catch (ServerException ex)
         {
             _logger.LogError(ex, "ServerException");
             throw ex;
         }
         catch (ClientException ex)
         {
             _logger.LogError(ex, "ClientException");
             throw ex;
         }
     });
 }
        public static SingleSendMailResponse Unmarshall(UnmarshallerContext context)
        {
            SingleSendMailResponse singleSendMailResponse = new SingleSendMailResponse();

            singleSendMailResponse.HttpResponse = context.HttpResponse;
            singleSendMailResponse.RequestId    = context.StringValue("SingleSendMail.RequestId");

            return(singleSendMailResponse);
        }
        public static SingleSendMailResponse Unmarshall(UnmarshallerContext context)
        {
            SingleSendMailResponse singleSendMailResponse = new SingleSendMailResponse();

            singleSendMailResponse.HttpResponse = context.HttpResponse;
            singleSendMailResponse.RequestId = context.StringValue("SingleSendMail.RequestId");

            return singleSendMailResponse;
        }
Exemplo n.º 9
0
        public bool SendEmail(string email, string fromAlias, string subject, string message, out string err)
        {
            var isSuccessful       = false;
            var regionID           = _appSettings.RegionID;
            var aliAccessKey       = _appSettings.AliAccessKey;
            var aliAccessKeySecret = _appSettings.AliAccessKeySecret;
            var aliMailAccount     = _appSettings.AliMailAccount;

            IClientProfile        profile = DefaultProfile.GetProfile(regionID, aliAccessKey, aliAccessKeySecret);
            IAcsClient            client  = new DefaultAcsClient(profile);
            SingleSendMailRequest request = new SingleSendMailRequest();

            try
            {
                request.AccountName    = aliMailAccount;
                request.FromAlias      = fromAlias;
                request.AddressType    = 1;
                request.ReplyToAddress = true;
                request.ToAddress      = email;
                request.Subject        = subject;
                request.HtmlBody       = message;
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                if (httpResponse.HttpResponse.Status == 200)
                {
                    err          = "send email successfully";
                    isSuccessful = true;
                }
                else
                {
                    err          = "failed, status code:" + httpResponse.HttpResponse.Status.ToString();
                    isSuccessful = false;
                }
            }
            catch (ServerException ex)
            {
                err          = ex.Message;
                isSuccessful = false;
            }
            catch (ClientException ex)
            {
                err          = ex.Message;
                isSuccessful = false;
            }
            return(isSuccessful);
        }
Exemplo n.º 10
0
        private void btnEmailReset_Click(object sender, EventArgs e)
        {
            Random rd = new Random();

            newpassword = (rd.Next(10000000, 100000000)).ToString();//随机生成一个8位数字密码
            DataSet ds = DBOperate.readDB("select * from UserInfo where UserEmail='" + txtEmailReset.Text.Trim() + "'");

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (DBOperate.writeDB("update UserInfo set UserPassword='******' where UserEmail='" + txtEmailReset.Text.Trim() + "'") > 0)
                {
                    IClientProfile        profile = DefaultProfile.GetProfile("cn-hangzhou", "阿里云", "密钥");
                    IAcsClient            client  = new DefaultAcsClient(profile);
                    SingleSendMailRequest request = new SingleSendMailRequest();
                    try
                    {
                        String pass = "******";width:99.8%;height:99.8%\";><tbody><tr><td style=\";background:#fafafa url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAy0lEQVQY0x2PsQtAYBDFP1keKZfBKIqNycCERUkMKLuSgZnRarIpJX8s3zfcDe9+794du+8bRVHQOI4wDAOmaULTNDDGYFkWMVVVQUTQdZ3iOMZxHCjLElVV0TRNYHVdC7ptW6RpSn3f4wdJkiTs+w6WJAl4DcOAbdugKAq974umaRAEARgXn+cRW3zfFxuiKCJZloXGHMeBbdv4Beq6Duu6Issy7iYB8Jbnucg8zxPLsggnj/zvIxaGIXmeB9d1wSE+nOeZf4HruvABUtou5ypjMF4AAAAASUVORK5CYII=)\";><div style=\";border-radius:10px;font-size:13px;color:#555;width:666px;font-family:'Century Gothic','Trebuchet MS','Hiragino Sans GB','微软雅黑','Microsoft Yahei',Tahoma,Helvetica,Arial,SimSun,sans-serif;margin:50px auto;border:1px solid #eee;max-width:100%;background:#fff repeating-linear-gradient(-45deg,#fff,#fff 1.125rem,transparent 1.125rem,transparent 2.25rem);box-shadow:0 1px 5px rgba(0,0,0,.15)\";><div style=\";width:100%;background:#49BDAD;color:#fff;border-radius:10px 10px 0 0;background-image:-moz-linear-gradient(0deg,#43c6b8,#ffd1f4);background-image:-webkit-linear-gradient(0deg,#43c6b8,#ffd1f4);height:66px\";><p style=\";font-size:15px;word-break:break-all;padding:23px 32px;margin:0;background-color:hsla(0,0%,100%,.4);border-radius:10px 10px 0 0\";>尊敬的图书馆管理系统用户您好:</p></div><div style=\";margin:40px auto;width:90%\";><p>" + newpassword + "是您的新密码,请牢记</p><p>请注意:此邮件自动发送,请勿直接回复。</p></div></div></td></tr></tbody></table>";
                        request.AccountName    = "你的发信域名";
                        request.FromAlias      = "图书管理系统";
                        request.AddressType    = 1;
                        request.TagName        = "BackPassword";
                        request.ReplyToAddress = true;
                        request.ToAddress      = (txtEmailReset.Text.Trim()).ToString();
                        request.Subject        = "图书管理系统的重置后密码";
                        request.HtmlBody       = pass;
                        SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                    }
                    finally
                    {
                        MessageBox.Show("邮件发送成功,如未收到请联系系统管理员或者在垃圾箱中寻找");
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("重置失败,请联系系统管理员!");
                }
            }
            else
            {
                MessageBox.Show("请输入注册过该平台的电子邮箱");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 精准发送(toAddress逗号分隔)一封一封发每日2000封上限
        /// </summary>
        /// <param name="fromEmail"></param>
        /// <param name="fromAlias"></param>
        /// <param name="toAddress"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="consoleTag"></param>
        /// <returns></returns>
        public void SendOneByOne(string fromEmail, string fromAlias, List <dynamic> recieveUsers, dynamic mailContent, string consoleTag)
        {
            Thread _thread = new Thread(new ParameterizedThreadStart(o =>
            {
                IClientProfile profile = DefaultProfile.GetProfile(m_regionId, m_accessKeyId, m_secret);
                IAcsClient client      = new DefaultAcsClient(profile);

                foreach (dynamic _user in recieveUsers)
                {
                    SingleSendMailRequest request = new SingleSendMailRequest();
                    try
                    {
                        request.AccountName    = fromEmail;
                        request.FromAlias      = fromAlias;
                        request.AddressType    = 1;
                        request.TagName        = consoleTag;
                        request.ReplyToAddress = true;
                        request.ToAddress      = _user.email;
                        request.Subject        = mailContent.subject;
                        request.HtmlBody       = string.Format(mailContent.content, _user.email_id, mailContent.msg_id);
                        SingleSendMailResponse httpResponse = client.GetAcsResponse(request);

                        var _reqId = httpResponse.RequestId;

                        //入库状态
                    }
                    catch (ServerException e)
                    {
                        //Console.WriteLine("服务器异常:" + e.Message);
                        //记录日志
                    }
                    catch (ClientException e)
                    {
                        //Console.WriteLine("客户端异常:" + e.Message);
                        //记录日志
                    }

                    Thread.Sleep(200);
                }
            }));

            _thread.Start(null);
        }
Exemplo n.º 12
0
        public bool SingleSendMail(SingleSendMailModel model)
        {
            var                   regionId    = ConfigHelper.GetValuesByKey("EmailRegionId");
            var                   accessKeyId = ConfigHelper.GetValuesByKey("EmailAccessKeyId");
            var                   secret      = ConfigHelper.GetValuesByKey("EmailSecret");
            IClientProfile        profile     = DefaultProfile.GetProfile(regionId, accessKeyId, secret);
            IAcsClient            client      = new DefaultAcsClient(profile);
            SingleSendMailRequest request     = new SingleSendMailRequest();

            try
            {
                request.AccountName    = model.AccountName;
                request.FromAlias      = model.FromAlias;
                request.AddressType    = model.AddressType;
                request.TagName        = model.TagName;
                request.ReplyToAddress = model.ReplyToAddress;
                request.ToAddress      = model.ToAddress;
                request.Subject        = model.Subject;
                if (model.EmailBodyType == EmailBodyType.Html)
                {
                    request.HtmlBody = model.EMailBody;
                }
                else
                {
                    request.TextBody = model.EMailBody;
                }
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
                return(httpResponse.HttpResponse.Status == 200);
            }
            catch (ServerException e)
            {
                LogHelper.Logger.Error(string.Format(MessageTips.SendEmailFail, "服务端原因", e.Message), e);
                throw new SendEmailException(string.Format(MessageTips.SendEmailFail, "服务端原因", e.Message), e);
            }
            catch (ClientException e)
            {
                LogHelper.Logger.Error(string.Format(MessageTips.SendEmailFail, "客服端原因", e.Message), e);
                throw new SendEmailException(string.Format(MessageTips.SendEmailFail, "客服端原因", e.Message), e);
            }
        }
Exemplo n.º 13
0
        ///<param name="toMail">收件人地址(可以是多个收件人,程序中是以“;"进行区分的)</param>
        ///<param name="subject">邮件标题</param>
        ///<param name="emailBody">邮件内容(可以以html格式进行设计)</param>
        ///<param name="sslEnable">true表示对邮件内容进行socket层加密传输,false表示不加密</param>
        public void Send(string toMail, string subject, string emailBody)
        {
            IClientProfile        profile = DefaultProfile.GetProfile("cn-hangzhou", AccessKeyId, AccessKeySecret);
            IAcsClient            client  = new DefaultAcsClient(profile);
            SingleSendMailRequest request = new SingleSendMailRequest();

            try
            {
                request.AccountName = Mail;
                request.FromAlias   = "红酒世界";
                request.AddressType = 1;
                //request.TagName = "控制台创建的标签";
                request.ReplyToAddress = true;
                request.ToAddress      = toMail;
                request.Subject        = subject;
                request.HtmlBody       = emailBody;
                SingleSendMailResponse httpResponse = client.GetAcsResponse(request);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }