private async Task <SendResponse> sendEmail(IFluentEmail email, ClientConfiguration clientConfig) { var option = new SmtpClientOptions(); if (!string.IsNullOrEmpty(this.config["Email:DevMode"]) && this.config["Email:DevMode"] == "true") { option.Server = "localhost"; option.User = ""; option.Password = ""; option.Port = 25; option.RequiresAuthentication = false; option.UseSsl = false; } else { option.Server = clientConfig.Server; option.User = clientConfig.EmailUserName; option.Password = clientConfig.EmailPassword; option.Port = clientConfig.Port; option.RequiresAuthentication = clientConfig.RequiresAuthentication; option.UseSsl = clientConfig.UseSsl; } email.Sender = new MailKitSender(option); var status = await email.SendAsync(); return(status); }
public async Task Send(string title, string message) { var messageWithDateTime = $"{message} ({DateTime.Now})"; // Send push notification if (_config.AzurePushNotifications != null && _config.AzurePushNotifications.Enabled) { var hub = NotificationHubClient.CreateClientFromConnectionString(_config.AzurePushNotifications.ConnectionString, _config.AzurePushNotifications.NotificationHubName); var payload = JsonConvert.SerializeObject(new AzureNotificationPayload(title, messageWithDateTime)); await hub.SendFcmNativeNotificationAsync(payload); } // Send email notification if (_config.EmailNotifications != null && _config.EmailNotifications.Enabled) { var emailConfig = _config.EmailNotifications; if (emailConfig.Recipients != null) { var authenticationEnabled = emailConfig.SmtpAuthentication != null && emailConfig.SmtpAuthentication.Enabled; var smtpClientOptions = new SmtpClientOptions() { Server = emailConfig.SmtpServerAddress, Port = emailConfig.SmtpServerPort, UseSsl = authenticationEnabled, RequiresAuthentication = authenticationEnabled, }; if (authenticationEnabled) { smtpClientOptions.User = emailConfig.SmtpAuthentication.UserName; smtpClientOptions.Password = emailConfig.SmtpAuthentication.Password; } Email.DefaultSender = new MailKitSender(smtpClientOptions); var recipientAddresses = _config.EmailNotifications.Recipients.Select(r => { var address = new MailAddress(r); return(new Address(address.Address, address.DisplayName)); } ); var senderAddress = new MailAddress(_config.EmailNotifications.Sender); var email = await Email.From(senderAddress.Address, senderAddress.DisplayName) .To(recipientAddresses.ToList()) .Subject(title) .Body(messageWithDateTime) .SendAsync(); } } }
static async System.Threading.Tasks.Task Main(string[] args) { string emailToken = File.ReadAllText("../../../../Settings.txt"); var option = new SmtpClientOptions { Account = "*****@*****.**", Token = emailToken, Host = "smtp.163.com", Port = 465, EnableSsl = false }; var em = new EmailService(option); Reminder reminder = new Reminder(new DbFileServices(), em, new Scanner()); reminder.AddBooksUrl("http://www.biquge.se/23609/"); reminder.AddReceiver("*****@*****.**"); await reminder.StartAsync(); }
public static IServiceCollection AddSmtpClientEmailNotification(this IServiceCollection services, SmtpClientOptions options) { services.AddSingleton <IEmailNotification>(new SmtpClientEmailNotification(options)); return(services); }
public static IServiceCollection AddSmtpClient(this IServiceCollection services, SmtpClientOptions options) { return(services.AddTransient <ISmtpClientService>(factory => { return new SmtpClientService(options); })); }
public static FluentEmailServicesBuilder AddMailKitSender(this FluentEmailServicesBuilder builder, SmtpClientOptions smtpClientOptions) { builder.Services.TryAdd(ServiceDescriptor.Scoped <ISender>(x => new MailKitSender(smtpClientOptions))); return(builder); }