Exemple #1
0
        public static string SendEmailByList(SendCloud sc)
        {
            try
            {
                HttpClient client = new HttpClient();
                HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));

                MultipartEntity multipartEntity = new MultipartEntity();
                postMethod.Entity = multipartEntity;

                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", sc.API_User));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", sc.API_Key));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", sc.From));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", sc.FromName));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", string.Join(" ", sc.listSubject.ToArray())));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", sc.Template));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "use_maillist", "true"));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "to", sc.To));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "label", sc.Label));

                HttpResponse response = client.Execute(postMethod);

                return response.ResponseCode.ToString();
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }
Exemple #2
0
        public static bool SendSMS(SendCloud sc)
        {
            try
            {
                string sVar = GetVarJson(sc.listVar[0]);

                StringBuilder sb = new StringBuilder();
                sb.Append(sc.API_Key).Append("&");
                sb.Append("phone=").Append(sc.To).Append("&");
                sb.Append("smsUser="******"&");
                sb.Append("templateId=").Append(sc.Template).Append("&");
                sb.Append("vars=").Append(sVar).Append("&");
                sb.Append(sc.API_Key);
                string sSignature = Encryption.UserMd5(sb.ToString());

                HttpClient client = new HttpClient();
                HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/smsapi/send"));

                MultipartEntity multipartEntity = new MultipartEntity();
                postMethod.Entity = multipartEntity;

                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "smsUser", sc.API_User));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "signature", sSignature));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "templateId", sc.Template));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "phone", sc.To));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "vars", sVar));

                HttpResponse response = client.Execute(postMethod);

                if (response.ResponseCode == 200)
                {
                    string entity = EntityUtils.ToString(response.Entity);
                    Hashtable ht = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Hashtable>(entity);
                    if ((string)ht["message"] == "请求成功" && (bool)ht["result"])
                        return true;
                    else
                        return false;
                }
                else
                    return false;
            }
            catch (Exception e)
            {
                return false;
            }
        }
Exemple #3
0
        public static bool SendEmail(SendCloud sc)
        {
            bool result = false;
            int iPageSize = 100;
            int iPageCount = sc.listVar.Count / iPageSize + (sc.listVar.Count % iPageSize == 0 ? 0 : 1);
            for (int i = 0; i < iPageCount; i++)
            {
                try
                {
                    string sVar = GetVarJson(sc.listVar.GetRange(i * iPageSize, i == iPageCount - 1 ? sc.listVar.Count - iPageSize * i : iPageSize));
                    sVar = sVar.Replace("\r", "").Replace("\n", "");

                    HttpClient client = new HttpClient();
                    HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));

                    MultipartEntity multipartEntity = new MultipartEntity();
                    postMethod.Entity = multipartEntity;

                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", sc.API_User));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", sc.API_Key));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", sc.From));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", sc.FromName));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", string.Join(" ", sc.listSubject.ToArray())));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", sc.Template));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "label", sc.Label));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "substitution_vars", sVar));

                    HttpResponse response = client.Execute(postMethod);
                    //result += sVar + Environment.NewLine;

                    if (response.ResponseCode == 200)
                        result = true;
                    //{
                    //    result += EntityUtils.ToString(response.Entity) + Environment.NewLine + "==============" + Environment.NewLine;
                    //}
                    //else
                    //    result += response.ResponseCode.ToString() + Environment.NewLine + "==============" + Environment.NewLine;
                }
                catch (Exception ex)
                {
                    //return ex.ToString();
                }
            }
            return result;
        }