Пишу программу для отправки e-mail - C#
Формулировка задачи:
Люди кто знает или сталкивался с проблемой SMTp серверов пишу прогу для отправки мыла
очень нужен адресок бесплатного SMTP сервера
Решение задачи: «Пишу программу для отправки e-mail»
textual
Листинг программы
- try
- {
- MailAddress maTo = new MailAddress(_recipient_address);
- MailAddress maFrom = new MailAddress(_senderAddress, _displayName);
- MailMessage mailMessage = new MailMessage(maFrom, maTo);
- mailMessage.IsBodyHtml = true;
- mailMessage.Body = TEXTMESSAGE;
- mailMessage.Subject = Res.SendTestMessage;
- SmtpClient client = new SmtpClient(_hostName);
- int port = 25;
- Int32.TryParse(_port, out port);
- bool enableSsl = true;
- Boolean.TryParse(_requiresSsl, out enableSsl);
- client.EnableSsl = enableSsl;
- bool defaultCredentials = true;
- Boolean.TryParse(_defaultCredentials, out defaultCredentials);
- client.UseDefaultCredentials = defaultCredentials;
- if (!defaultCredentials)
- {
- NetworkCredential credential = new NetworkCredential()
- {
- UserName = _username,
- Password = _password
- };
- client.Credentials = credential;
- }
- _currentUiCulture = Thread.CurrentThread.CurrentUICulture;
- client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
- object[] userToken = new object[] { TEXTMESSAGE, _recipient_address };
- client.SendAsync(mailMessage, userToken);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message, "Send", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
- {
- if (_currentUiCulture != null)
- Thread.CurrentThread.CurrentUICulture = _currentUiCulture;
- string mailMessage = String.Empty;
- object[] userToken = e.UserState as object[];
- if (e.Error != null)
- {
- Console.WriteLine(e.Error.Message.ToString());
- MessageBox.Show(e.Error.Message.ToString(), "Send", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else if (e.Cancelled)
- {
- Console.WriteLine(e.Cancelled.ToString());
- MessageBox.Show(mailMessage, "Send", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- mailMessage = String.Format(Res.SendTestMessageTextMessageBox, _recipient_address);
- Console.WriteLine(mailMessage);
- MessageBox.Show(mailMessage, "Send", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д