Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static async void SendEmail(LogFileType logType, SendLogJob job)
- {
- #region EMAIL_CONSTANTS
- string From = "abc@company.com";
- string To = "username@domain.com";
- #endregion
- try
- {
- MailAddress fromUsername = new MailAddress(From);
- MailAddress from = new MailAddress(From, "Auto Generated Mail", System.Text.Encoding.UTF8);
- MailAddress to = new MailAddress(To);
- const string fromPassword = "1234";
- var smtp = new SmtpClient
- {
- Host = "mail3.gridhost.co.uk",
- Port = 465,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromUsername.Address, fromPassword)
- };
- var message = new MailMessage(from, to)
- {
- Subject = "Subject of the Email goes here",
- Body = "This is the EMail Body",
- IsBodyHtml=true,
- SubjectEncoding = System.Text.Encoding.UTF8,
- BodyEncoding = System.Text.Encoding.UTF8
- };
- smtp.SendCompleted += (s, e) =>
- {
- SendCompletedCallback(s, e);
- smtp.Dispose();
- message.Dispose();
- };
- MemoryStream stream = new MemoryStream(new byte[64000]);
- Attachment attachment = new Attachment(stream, logType + " File");
- message.Attachments.Add(attachment);
- smtp.SendAsync(message, message);
- }
- catch (Exception ex)
- {
- ex.Message.ToString();
- }
- Syntax error, command unrecognized. The server response was:
- at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement