public void SendTest() { string from = "*****@*****.**"; string[] to = new[] { "*****@*****.**" }; string[] cc = new[] { "*****@*****.**" }; string subject = "SmtpUtility のテスト"; string body = "SmtpUtility のテストです。\r\n\r\n3 行目です。\r\n"; SmtpUtility.Send(from, to, cc, subject, body); Assert.Inconclusive("電子メールを受信したことを確認してください。"); }
private static async Task <ActionResponse> DoSend(string MailFrom, string RcptTo, string MessageContent) { var setting = await SmtpUtility.GetSendSetting(Data.AppSettings.ServerSetting, Data.AppSettings.IsOnlineServer, MailFrom, RcptTo); if (!setting.OkToSend) { return(new ActionResponse() { Success = false, Message = setting.ErrorMessage, ShouldRetry = false }); } using (var sendClient = new Kooboo.Mail.Smtp.SmtpClient(setting.LocalIp)) { if (setting.UseKooboo) { await sendClient.Connect(setting.KoobooServerIp, setting.Port); } else { foreach (var item in setting.Mxs) { try { await sendClient.Connect(item, 25); break; } catch (System.Exception ex) { Kooboo.Mail.Smtp.Log.LogInfo(ex.Message + ex.StackTrace + ex.Source); } } } if (!sendClient.Connected) { string msg = "Can not connect to remote mail server"; return(new ActionResponse() { Success = false, ShouldRetry = true, Message = msg }); } return(await Send(sendClient, MailFrom, RcptTo, MessageContent, setting)); } }
private async void okButton_Click(object sender, System.EventArgs e) { okButton.Visible = false; cancelButton.Visible = false; loadingPictureBox.Start(); loadingPictureBox.Visible = true; string email = emailTextBox.Text; using (SqlDataReader dataReader = await SqlUtility.Read("SELECT [email], [name] FROM [users] WHERE [email] = @email;", new string[] { email }, delegate(SqlException ex1) { StopLoading(); })) { if (dataReader == null) { return; } if (!await dataReader.ReadAsync()) { StopLoading(); MessageBox.Show("Email not linked to any account!", ChatAppForm.TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string resetCode = new Random().Next(0x100000, 0xffffff + 1).ToString("X").ToLower(); if (!await SmtpUtility.Send(email, "Password reset", "Hello " + dataReader.GetString(1) + ",\n\n" + "Please use the following reset code to reset the password of your account.\n\n" + "Reset code: #" + resetCode, delegate(SmtpException ex2) { StopLoading(); })) { return; } StopLoading(); SwitchTo(new ResetCodePage(email, resetCode), SWITCH_LEFT); } }
public async Task <List <ImapResponse> > Execute(ImapSession session, string args) { var appendArgs = ParseArgs(args); if (appendArgs == null) { throw new CommandException("BAD", "Error in arguments"); } await session.Stream.WriteLineAsync("+ Continue"); var bytes = await session.Stream.ReadAsync(appendArgs.Size); var content = SmtpUtility.GetString(bytes); await session.Stream.ReadLineAsync(); var message = MessageUtility.ParseMeta(content); message.FolderId = session.SelectFolder.FolderId; message.UserId = session.MailDb.UserId; var folderName = session.SelectFolder.Folder.ToLower(); if (folderName == "sent" || folderName == "drafts") { var user = Data.GlobalDb.Users.Get(session.MailDb.UserId); var orgDb = Kooboo.Mail.Factory.DBFactory.OrgDb(user.CurrentOrgId); var address = orgDb.EmailAddress.Get(Mail_t_Mailbox.Parse(message.From).Address); if (address != null) { message.AddressId = address.Id; } } session.MailDb.Messages.Add(message, content); return(null); }
private async void signUpButton_Click(object sender, EventArgs e) { signUpButton.Visible = false; cancelButton.Visible = false; loadingPictureBox.Start(); loadingPictureBox.Visible = true; string email = emailTextBox.Text; using (SqlDataReader dataReader = await SqlUtility.Read("SELECT [email] FROM [users] WHERE [email] = @email;", new string[] { email }, OnException)) { if (dataReader == null) { return; } if (!Validate(emailTextBox, await dataReader.ReadAsync(), "Email should not be linked to another account!")) { StopLoading(); return; } } string name = nameTextBox.Text, verificationCode = new Random().Next(0x100000, 0xffffff + 1).ToString("X").ToLower(); if (!await SmtpUtility.Send(email, "Welcome", "Hello " + name + ",\n\n" + "Welcome to Chat App! Please verify your account using the following verification code.\n\n" + "Verification code: #" + verificationCode, delegate(SmtpException ex) { StopLoading(); })) { return; } loadingPictureBox.Pause(); EmailVerificationForm verificationForm = new EmailVerificationForm(verificationCode); verificationForm.ShowDialog(); verificationForm.Dispose(); if (verificationForm.DialogResult != DialogResult.OK) { StopLoading(); SwitchToSignIn(); return; } loadingPictureBox.Resume(); if (await SqlUtility.Write("INSERT INTO [users] ([email], [name], [password]) VALUES (@email, @name, @password);", new string[] { email, name, passwordTextBox.Text }, OnException) != 1) { return; } StopLoading(); MessageBox.Show("Sign up successful!", ChatAppForm.TITLE, MessageBoxButtons.OK, MessageBoxIcon.Information); SwitchToSignIn(); }