Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

How to send smtp email without entering credentials (which often change)?

$
0
0

I wrote the code below which works great. The code will be run on a schedule ( daily and/or weekly ) to process files and send an email at the end of processing with an attachment of results. However this code requires network credentials (user and password). However the password often changes. So how do i write the code to send the email without having to go in and change mmy code when the password changes?

  Dim SmtpServer As New SmtpClient()
  SmtpServer.EnableSsl = True
  Dim mail As New MailMessage()
  SmtpServer.Credentials = New Net.NetworkCredential("dw@my-org.org", "mypassword")
  SmtpServer.Port = 587
  SmtpServer.Host = "smtp.office365.com"
  mail = New MailMessage()
  mail.From = New MailAddress("dw@my-org.org")
  mail.To.Add("dw@my-org.org")
  mail.Subject = "Results of automatic Import of Time Card Punches to Attendance Application"
  mail.Body = "Attached are the CSV logs with the results of the automatic Import of Time Card Punches to Attendance Application. The import file contains logs of any new employee records createds or any changes to any existing employees. The import issues file will not contain any results unless there were errors during import."
  mail.Attachments.Add(New Attachment(LogFilename.ToString))
  mail.Attachments.Add(New Attachment(LogimportIssues.ToString))
  SmtpServer.Send(mail)

Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>