当前位置: 首页>>代码示例>>C#>>正文


C# Email.Authenticate方法代码示例

本文整理汇总了C#中Email.Authenticate方法的典型用法代码示例。如果您正苦于以下问题:C# Email.Authenticate方法的具体用法?C# Email.Authenticate怎么用?C# Email.Authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Email的用法示例。


在下文中一共展示了Email.Authenticate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendEmails


//.........这里部分代码省略.........
                                            }
                                        }
                                    }
                                    else if (nextUpdateRequest != null)
                                    {
                                        // send email if sent date is not null and later than x days after sent
                                        if (nextUpdateRequest.LastSentDate.HasBeenSet() == false)
                                        {
                                            shouldSendEmail = true;
                                        }
                                        else if (nextUpdateRequest.LastSentDate.TimeUntilNow().Minutes > importTask.ImportTaskConfiguration.DaysBetweenEmails)
                                        {
                                            shouldSendEmail = true;
                                        }
                                        else if (nextUpdateRequest.LastSentDate.TimeUntilNow().Minutes > importTask.ImportTaskConfiguration.DaysUntilEmailReminder)
                                        {
                                            isReminder = true;
                                            shouldSendEmail = true;
                                        }
                                    }

                                    if (shouldSendEmail)
                                    {
                                        // create new update request
                                        employee.Reload();
                                        UpdateRequest nextRequest = importTask.UpdateRequestForEmployeeWithStep(lastStepCompleted + 1, employee);

                                        if (nextRequest != null)
                                        {
                                            ImportTaskEmail email = importTask.ImportTaskConfiguration.ImportTaskEmails.ToList<ImportTaskEmail>().Where(x => x.Step == nextStep).FirstOrDefault();
                                            string emailLink = Utilities.Domain() + UrlManager.EmployeeEditWithRequestUpdateOid(nextRequest.Oid);

                                            string name = String.IsNullOrEmpty(employee.FullName()) ? "there" : employee.FullName();
                                            string subject = String.IsNullOrEmpty(email.Subject) == false ? email.Subject : "Update your data";
                                            subject = subject.Replace(EmployeeFullNamePlaceHolder, name);

                                            if (isReminder)
                                            {
                                                subject += " (Reminder)";
                                            }

                                            string emailText = email.EmailText;
                                            string toEmail = employee.EmailAddress;

                                            string body = emailText + "<br/>" + emailLink;
                                            body = body.Replace(EmployeeFullNamePlaceHolder, employee.FullName());

                                            Email mail = new Email()
                                            {
                                                Subject = subject,
                                                ToEmail = toEmail,
                                                Body = body
                                            };

                                            ValidationResult validation = new EmailValidator().Validate(mail);

                                            if (validation.IsValid == true)
                                            {
                                                if (nextRequest.OriginalSentDate.HasBeenSet() == false)
                                                {
                                                    nextRequest.OriginalSentDate = DateTime.Now;
                                                }

                                                nextRequest.LastSentDate = DateTime.Now;
                                                nextRequest.TimesSent++;
                                                nextRequest.Save();
                                                Debug.WriteLine("Sending email to: " + toEmail + " with body: " + body);

                                                if (toEmail == "[email protected]")
                                                {
                                                    mail.Authenticate("[email protected]", "yfwlmyeevmvbdbjq").Send();
                                                }

                                                emailsSent++;
                                            }
                                            else
                                            {
                                                Debug.WriteLine("Error sending email to: " + toEmail + " with error: " + String.Join(",", validation.Errors));
                                            }
                                        }
                                        else
                                        {
                                            Debug.WriteLine("Next request was null - meaning employee is done.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                session.Disconnect();
                session.Dispose();
                Debug.Write(emailsSent + " would be sent /n");
            }
            catch (Exception e)
            {
                Debug.Write("background email task threw ex" + e);
            }
        }
开发者ID:a1exb1,项目名称:farlon-data-consolidator-dotnet,代码行数:101,代码来源:SendEmailsBackgroundTask.cs


注:本文中的Email.Authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。