Beispiel #1
0
        public static bool SendRegisterActivation(Data_AppUserFile user, LogForEmailSend log)
        {
            try
            {
                string to               = user.Email;
                string subject          = "Register with NiceApi.net";
                string htmlBodyNoHeader = EMail_Data.GetRegistrationEmailBody("https://NiceApi.net/Register?ApiGuId=" + Base64_URLEncoding(user.ApiGuId));
                string error;

                bool ret = Send(EMailCredentials.GetSupport(), to, subject, htmlBodyNoHeader, out error, log, "Verify Please");
                return(ret);
            }
            catch (SystemException)
            {
            }
            return(false);
        }
Beispiel #2
0
        public static bool Send(EMailCredentials from, string to, string bcc, string subject, string htmlBodyNoHeader, out string errorText, LogForEmailSend log, string logId)
        {
            EMailCredentials cred = from;

            errorText = "";

            if ((to == null) && (bcc != null))
            {
                // no to set but a bcc, so swap
                to  = bcc;
                bcc = null;
            }

            MailMessage mail = new MailMessage();

            mail.To.Add(to);
            if (bcc != null)
            {
                mail.Bcc.Add(bcc);
            }
            mail.From            = cred.From;
            mail.Subject         = subject;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body            = EMail_Data.GetHeaderHtml() + htmlBodyNoHeader + EMail_Data.GetFooterHtml();
            mail.BodyEncoding    = System.Text.Encoding.UTF8;
            mail.IsBodyHtml      = true;
            mail.Priority        = MailPriority.High;

            if ("SendEmailToDataport".IsAppSettingsTrue())
            {
                using (MemoryStream ms = mail.RawMessage())
                {
                    CSC.DataLoggerAccess.Send(ms.ToArray());
                }
                return(true);
            }
            else
            {
                SmtpClient client = new SmtpClient();
                client.Credentials = cred.NetCredential;
                client.Port        = cred.Port;
                client.Host        = cred.Host;
                client.EnableSsl   = cred.EnableSsl;
                try
                {
                    client.Send(mail);
                    log.Log.Info(logId + " to " + to);
                    return(true);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(ex.ToString());
                    sb.AppendLine(ex.Message);
                    Exception ex2 = ex;
                    while (ex2 != null)
                    {
                        sb.AppendLine(ex2.ToString());
                        ex2 = ex2.InnerException;
                    }
                    errorText = sb.ToString();
                    log.Log.Error(logId + " to " + to + " " + errorText);
                }
            }
            return(false);
        }