Exemplo n.º 1
0
        public static bool SendMail(string to, string subject, string body, bool isBodyHtml, List <Attachment> attachments = null)
        {
            try
            {
                var filePath = Basic.AssemblyDirectory + "\\" + "Email.txt";
                if (File.Exists(filePath))
                {
                    var data = File.ReadAllText(filePath);

                    var datas = data.Split(';');

                    var smtpDatas = datas[0].Split(':');

                    _smtpUrl = smtpDatas[0];

                    _smtpPort = smtpDatas[1];

                    _email = datas[1];

                    _pass = datas[2];
                }
                else
                {
                    File.WriteAllText(filePath, $"{_smtpUrl}:{_smtpPort};{_email};{_pass}");
                }

                return(SendMail(_email, to, subject, body, isBodyHtml, attachments));
            }
            catch (Exception ex)
            {
                ExceptionReport.log(ex);
                throw new Exception("Email file not configured correctly.\r\n" + ex.Message);
            }
        }
Exemplo n.º 2
0
        public static string GetDataFromUrl(string url)
        {
            try
            {
                string         data    = "";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentType property of the WebRequest.
                request.UserAgent   = ".NET Framework Example Client";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (Stream receiveStream = response.GetResponseStream())
                    {
                        StreamReader readStream;
                        if (string.IsNullOrEmpty(response.CharacterSet))
                        {
                            readStream = new StreamReader(receiveStream ?? throw new InvalidOperationException());
                        }
                        else
                        {
                            readStream = new StreamReader(receiveStream ?? throw new InvalidOperationException(), Encoding.GetEncoding(response.CharacterSet));
                        }


                        data = readStream.ReadToEnd();
                        response.Close();
                        readStream.Close();
                    }
                }
                return(data);
            }
            catch (Exception ex)
            {
                //Log.Error(ex);
                ExceptionReport.log(ex);
                return(null);
            }
        }