コード例 #1
0
    protected void ButtonRecoverPassword_Click(object sender, EventArgs e)
    {
        string emailAddress = TextBox1.Text;
        // Get username from email
        string username = Utils.GetUsernameFromEmail(TextBox1.Text);
        if (String.IsNullOrEmpty(username))
        {
            LabelStatus.Text = "Email Address Not Found. Please Register.";
        }
        else
        {
            MembershipUser mu = Membership.GetUser(username);
            String newPassword = mu.ResetPassword();

            var msg = new EmailMessage(true, false);
            msg.Logging = false;
            msg.LogOverwrite = false;
            msg.LogPath = Context.Server.MapPath(String.Empty) + "\\App_Data\\EmailPasswordRecovery.log";
            msg.FromAddress = Utils.GetServiceEmailAddress();
            msg.To = emailAddress;
            msg.Subject = "Your New Password For http://www.siliconvalley-codecamp.com";

            if (msg.Server.Equals("smtp.gmail.com"))
            {
                var ssl = new AdvancedIntellect.Ssl.SslSocket();
                msg.LoadSslSocket(ssl);
                msg.Port = 587;
            }

            var sb = new StringBuilder();
            sb.AppendLine(
                String.Format("Please log in to your codecamp account ({0}) with the new password: {1}",
                              username, newPassword));
            sb.AppendLine(" ");
            sb.AppendLine("We suggest that after you log in, you change your password to something");
            sb.AppendLine("you will likely remember.  We store your password in an encrypted format which is");
            sb.AppendLine("why we are unable to send you your original password.");
            sb.AppendLine(" ");
            sb.AppendLine("We are looking forward to seeing you!");
            sb.AppendLine(" ");
            sb.AppendLine("Best Regards,");
            sb.AppendLine("The Code Camp Volunteers");
            sb.AppendLine("http://www.siliconvalley-codecamp.com");

            msg.Body = sb.ToString();

            msg.Send();
            LabelStatus.Text = "Password Sent to your registered email account.";
        }
    }
コード例 #2
0
        private void SendMailConfirmation(string contactEmail, string company, int id)
        {
            var sb = new StringBuilder();
               sb.AppendLine("email: " + contactEmail);
               sb.AppendLine("company:" + company);
               sb.AppendLine("url: " + "http://siliconvalley-codecamp.com/rest/SponsorRequest/" + id.ToString(CultureInfo.InvariantCulture));

               var msg = new EmailMessage(true, false);
               int portNumber = Convert.ToInt32(ConfigurationManager.AppSettings["EmailMessage.Port"]);
               msg.Port = portNumber;

               if (msg.Server.Equals("smtp.gmail.com"))
               {
               var ssl = new AdvancedIntellect.Ssl.SslSocket();
               msg.LoadSslSocket(ssl);
               msg.Port = 587;
               }

               msg.CharSet = "iso-8859-1";
               msg.Logging = true;
               msg.LogInMemory = true;
               msg.LogOverwrite = false;
               //msg.LogPath = logFile;
               msg.FromAddress = "*****@*****.**";
               msg.To = "*****@*****.**";
               msg.Subject = "Sponsorship Email From: " + company + " " + contactEmail;
               msg.Body = sb.ToString();

               try
               {
               msg.Send(true, false);
               }
               catch (Exception)
               {

              // throw;
               }

               var str = msg.Log;
        }
コード例 #3
0
    private void SendEmailToSpeakerJustBeforeEvent(string userFirstName, string userLastName, string email, string sessionTitle, string tweet)
    {
        var sb = new StringBuilder();

        sb.AppendLine(String.Format("Hi {0} {1} (Code Camp Speaker)", userFirstName, userLastName));
        sb.AppendLine(" ");
        sb.AppendLine(String.Format("Your Session {0} Has Been Tweeted With the agenda info!", sessionTitle));
        sb.AppendLine(" ");
        sb.AppendLine("You can now see your session on the Silicon Valley Code Camp Twitter Feed.  That feed can be found");
        sb.AppendLine("at the url: http://twitter.com/sv_code_camp .  Please subscribe to the twitter feed as well as ReTweet");
        sb.AppendLine("it so other will know about it.  Also, please note our Twitter hash tag included in that tweet is #svcc .");
        sb.AppendLine("If you do not have hash tags or your twitter handle (if you have one) in the tweet, please add them by editing your session.");
        sb.AppendLine(" ");

        sb.AppendLine("Thanks for speaking at code camp!  See you very soon.  Feel free to respond to this email if you have any questions.");
        sb.AppendLine(" ");
        sb.AppendLine("Regards,");
        sb.AppendLine("Your Code Camp Team");
        sb.AppendLine("http://siliconvalley-codecamp.com");

        try
        {
            var msg = new EmailMessage(true, false)
            {
                Logging = true,
                LogOverwrite = false,
                LogPath = MapPath(string.Empty) + "\\App_Data\\TwitterSend.log",
                FromAddress = Utils.GetServiceEmailAddress(),
                ReplyTo = Utils.GetServiceEmailAddress(),
                To = email,
                Subject = String.Format("Your Silicon Valley Code Camp Session Has Been Tweeted!"),
                Body = sb.ToString()
            };

            if (msg.Server.Equals("smtp.gmail.com"))
            {
                var ssl = new AdvancedIntellect.Ssl.SslSocket();
                msg.LoadSslSocket(ssl);
                msg.Port = 587;
            }
            if (!testMode)
            {
                msg.Send();
            }

        }
        catch (Exception)
        {

        }
    }
コード例 #4
0
    public void GenerateMails()
    {
        lock (Utils.MailLocker)
        {
            int delayPerEmailMilliSeconds = 0;
            if (emailsPerHour != 0)
            {
                delayPerEmailMilliSeconds = 3600000 / emailsPerHour;
            }

            DateTime startTime = DateTime.Now;
            var sbLog = new StringBuilder();
            sbLog.AppendLine("----------------START-------------------------------" + DateTime.Now);
            sbLog.AppendLine(String.Format("Email Delay in MilliSeconds {0}, Repeat Each Email: {1}",
                                           delayPerEmailMilliSeconds, repeatEachEmail));
            sbLog.AppendLine("Message Subject: " + subject);
            sbLog.AppendLine("Message From: " + fromEmail);
            sbLog.AppendLine("Message Body: " + body);

            var msg = new EmailMessage(true, false);
            int portNumber =  Convert.ToInt32(ConfigurationManager.AppSettings["EmailMessage.Port"].ToString());
            msg.Port = portNumber;

            if (msg.Server.Equals("smtp.gmail.com"))
            {
                var ssl = new AdvancedIntellect.Ssl.SslSocket();
                msg.LoadSslSocket(ssl);
                msg.Port = 587;
            }

            // using for instead of foreach cause it's easier to track start and end of list
            for (int i = 0; i < toEmailList.Count; i++)
            {
                try
                {
                    var cacheName = (string)cache[Utils.CacheMailCancelFlag];
                    if (!string.IsNullOrEmpty(cacheName))
                    {
                        if (((string)cache[Utils.CacheMailCancelFlag]).Equals("true"))
                        {
                            sbLog.AppendLine("Mail Send Cancelled By User");
                            cache[Utils.CacheMailSentStatusName] = "Mail Send Cancelled By User";
                            break;
                        }
                    }

                    msg.CharSet = "iso-8859-1";
                    msg.Logging = true;
                    msg.LogOverwrite = false;
                    msg.LogPath = logFile;
                    msg.FromAddress = fromEmail;
                    msg.To = toEmailList[i];
                    msg.Subject = subject;
                    string PKIDStr = string.Empty;
                    if (DictionaryOfPKIDsByEmail.ContainsKey(toEmailList[i]))
                    {
                        PKIDStr = DictionaryOfPKIDsByEmail[toEmailList[i]];
                    }

                    msg.Body = !String.IsNullOrEmpty(PKIDStr) ? body.Replace("{PKID}", PKIDStr) : body;
                }
                catch (Exception)
                {
                  // just skip any bad email here
                }

                for (int repeatCnt = 0; repeatCnt < repeatEachEmail;repeatCnt++ )
                {
                    try
                    {
                        if (i == 0 && toEmailList.Count == 1)
                        {
                            msg.Send();
                        }
                        else if (i == 0)
                        {
                            msg.Send(true, false);
                        }
                        else if (i == toEmailList.Count - 1)
                        {
                            msg.Send(false, true);
                        }
                        else
                        {
                            msg.Send(false, false);
                        }
                        string mailStatus = i + "Success Send To: " + msg.To;
                        // should really add with expiration but this is pretty small so not worring about it
                        cache[Utils.CacheMailSentStatusName] = mailStatus;
                        sbLog.AppendLine(mailStatus);
                        Thread.Sleep(delayPerEmailMilliSeconds);
                    }
                    catch (Exception eError)
                    {
                        sbLog.AppendLine(i + ":" + eError);
                    }
                }
            }

            DateTime stopTime = DateTime.Now;
            TimeSpan elapsedTime = stopTime - startTime;
            double milliSeconds = elapsedTime.TotalMilliseconds;

            sbLog.AppendLine();
            sbLog.AppendLine();
            sbLog.AppendLine(milliSeconds + " milliseconds");
            sbLog.AppendLine("----------------DONE-------------------------------" + DateTime.Now);

            var f = new FileInfo(logFileStatus);
            FileStream s = f.Open(FileMode.Append, FileAccess.Write);

            string str = sbLog.ToString();

            var ba = new byte[str.Length];
            ba = Encoding.ASCII.GetBytes(str);

            s.Write(ba, 0, ba.Length);
            s.Close();
        }
        cache[Utils.CacheMailSentStatusName] = "Mail Done";
    }
コード例 #5
0
    //CaptchaUltimateControl1_Verified
    protected void CaptchaUltimateControl1_Verified(object sender, EventArgs e)
    {
        string completionMessage = string.Empty;
        string sessionNamex = GetFromCaptchaControl("SessionNameID");
        string presenterName = GetFromCaptchaControl("PresenterNameID");
        string textBoxMessageString = GetFromCaptchaControl("TextBoxMessageID");

        var sb = new StringBuilder();

        //sb.AppendLine(String.Format("To: {0} ", presenterName ?? string.Empty));
        //sb.AppendLine(String.Format("From: {0} Sent Through Silicon Valley Code Camp", userEmail ?? string.Empty));
        //sb.AppendLine(String.Format("Subject: Your Session {0}", sessionNamex ?? string.Empty));
        sb.AppendLine(" ");
        sb.AppendLine(textBoxMessageString ?? string.Empty);
        sb.AppendLine(" ");
        sb.AppendLine("------------------------------------------------------- ");
        sb.AppendLine("Note From Code Camp:");
        sb.AppendLine(" ");
        sb.AppendLine(" ");
        sb.AppendLine(String.Format("This note was generated by user {0} pressing the 'Email Speaker Button' on your session: ", attendeeEmail));
        sb.Append(sessionTitle);
        sb.Append(" ");
        sb.Append(sessionURL);
        sb.AppendLine(" ");
        sb.AppendLine(" ");

        // todo: this needs to be person requesting
        sb.Append(String.Format("{0} {1} at email {2} does not have your email.  Please do not press the reply button. ",
            attendeeFirstName,attendeeLastName,attendeeEmail));

        sb.Append("To reply to this person, use the users ");
        sb.Append(String.Format("email address {0}.",attendeeEmail));
        sb.AppendLine(" ");
        sb.AppendLine(" ");
        sb.Append(
            "If you do not want user to be able to send you emails, log into your code camp account, choose 'My Profile' on the left sidebar, and check the box 'Do Not Display Email Speaker On My Session'. ");
        sb.AppendLine(" ");
        sb.AppendLine(" ");
        sb.AppendLine("Thanks for speaking at Silicon Valley Code Camp!");

        try
        {
            var msg = new EmailMessage(true, false)
                          {
                              Logging = true,
                              LogOverwrite = false,
                              LogPath = MapPath(string.Empty) + "\\App_Data\\SpeakerSend.log",
                              FromAddress = Utils.GetServiceEmailAddress(),
                              ReplyTo = attendeeEmail,
                              To = speakerEmail,
                              Subject =
                                  String.Format("Code Camp Email From Attendee: {0} {1} Email: {2} on your Session",
                                                userFirstName, userLastName, attendeeEmail),
                              Body = sb.ToString()
                          };

            if (msg.Server.Equals("smtp.gmail.com"))
            {
                var ssl = new AdvancedIntellect.Ssl.SslSocket();
                msg.LoadSslSocket(ssl);
                msg.Port = 587;
            }
            msg.Send();

            SetCaptchaControlLabel("LabelStatus", "Message Sent Successfully");
            HyperLinkHome.Visible = true;

        }
        catch (Exception ee)
        {
            SetCaptchaControlLabel("LabelStatus", "Message Did Not Send Correctly.  Sorry  Please email [email protected] for more help." + ee);
        }
    }
コード例 #6
0
        public HttpResponseMessage PostForgotPassword(AttendeesResult attendeesResult)
        {
            HttpResponseMessage response;

            string usernameOrEmail = attendeesResult.Username;


            string username = Utils.GetUsernameFromEmail(usernameOrEmail);
            if (String.IsNullOrEmpty(username))
            {
                string goodEmail = Utils.GetEmailFromUsername(usernameOrEmail);
                username = Utils.GetUsernameFromEmail(goodEmail);
            }

            if (String.IsNullOrEmpty(username))
            {
                response =
                    Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                                                "Name not found as either username or email.  Please register as new attendee");
            }
            else
            {
                var attendeeRec = AttendeesManager.I.Get(new AttendeesQuery {Username = username}).FirstOrDefault();
                if (attendeeRec == null)
                {
                    throw new ApplicationException("attendeeRec could not be loaded");
                }
                MembershipUser mu = Membership.GetUser(username);
                if (mu == null)
                {
                    throw new ApplicationException("MembershipUser mu not found");
                }
                var newPassword = mu.ResetPassword();
                var msg = new EmailMessage(true, false)
                    {
                        Logging = false,
                        LogOverwrite = false,
                        //LogPath = Context.Server.MapPath(String.Empty) + "\\App_Data\\EmailPasswordRecovery.log",
                        FromAddress = Utils.GetServiceEmailAddress(),
                        To = attendeeRec.Email,
                        Subject = "Your New Password For http://www.siliconvalley-codecamp.com"
                    };

                if (msg.Server.Equals("smtp.gmail.com"))
                {
                    var ssl = new AdvancedIntellect.Ssl.SslSocket();
                    msg.LoadSslSocket(ssl);
                    msg.Port = 587;
                }

                var sb = new StringBuilder();
                sb.AppendLine(
                    String.Format("Please log in to your codecamp account ({0}) with the new password: {1}",
                                  username, newPassword));
                sb.AppendLine(" ");
                sb.AppendLine("We suggest that after you log in, you change your password.");
                sb.AppendLine("We store your password in an encrypted format which is");
                sb.AppendLine("why we are unable to send you your original password.");
                sb.AppendLine(" ");
                sb.AppendLine("We are looking forward to seeing you at camp!");
                sb.AppendLine(" ");
                sb.AppendLine("Best Regards,");
                sb.AppendLine("");
                sb.AppendLine("http://www.siliconvalley-codecamp.com");

                msg.Body = sb.ToString();

                try
                {
                    msg.Send();
                    response =
                        Request.CreateResponse(HttpStatusCode.OK, new AttendeesResult()
                            {
                                Email = attendeeRec.Email,
                                Username = attendeeRec.Username,
                                Id = attendeeRec.Id
                            });
                }
                catch (Exception e)
                {
                    response =
                        Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                                                    "We found your account but email could not be delivered to " +
                                                    attendeeRec.Email + " for account " + attendeeRec.Username +
                                                    ".  Please Make a new account or contact [email protected] and we will reset the password for you.");
                }
            }
            return response;
        }
コード例 #7
0
        /// <summary>
        /// phai truyen property cho FromName va FromAddress
        /// Default: FromName=Chudu24,[email protected]
        /// </summary>
        /// <param name="FromName"></param>
        /// <param name="FromAddress"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="cc"></param>
        /// <param name="bcc"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="SmtpServer"></param>
        /// <param name="SmtpUserName"></param>
        /// <param name="SmtpPassword"></param>
        /// <param name="SmtpPort"></param>
        /// <param name="SmtpUseSsl"></param>
        /// <returns></returns>
        private bool Send2(string FromName, string FromAddress, string from, string to, string cc, string bcc, string subject, string body
           , string SmtpServer, string SmtpUserName, string SmtpPassword, int SmtpPort, bool SmtpUseSsl)
        {
            EmailMessage _EmailMessage = new EmailMessage();
            _EmailMessage.Server = SmtpServer;
            if (!String.IsNullOrEmpty(SmtpUserName)) _EmailMessage.Username = SmtpUserName;
            if (!String.IsNullOrEmpty(SmtpPassword)) _EmailMessage.Password = SmtpPassword;
            if (SmtpPort != 0) _EmailMessage.Port = SmtpPort;
            if (SmtpUseSsl) _EmailMessage.LoadSslSocket(new AdvancedIntellect.Ssl.SslSocket()); // create the ssl socket

            //Trace.Warn("_EmailMessage.Server", _EmailMessage.Server);
            //Trace.Warn("_EmailMessage.Username", _EmailMessage.Username);
            //Trace.Warn("_EmailMessage.Password", _EmailMessage.Password);
            //Trace.Warn("_EmailMessage.Port", _EmailMessage.Port.ToString());

            _EmailMessage.FromAddress = FromAddress;
            _EmailMessage.FromName = FromName;
            _EmailMessage.To = to;
            if (!String.IsNullOrEmpty(cc)) _EmailMessage.Cc = cc;
            if (!String.IsNullOrEmpty(bcc)) _EmailMessage.Bcc = bcc;
            _EmailMessage.Subject = subject;
            _EmailMessage.Body = body;
            _EmailMessage.CharSet = "utf-8";
            _EmailMessage.BodyFormat = MailFormat.Html;

            return _EmailMessage.Send();
        }