Powershell to send email with delivery notification enabled

Powershell to send email with delivery notification enabled. Once mail is delivered to the recipient mailbox and delivery notification mail will be sent to the sender mailbox. Below powershell help you to atchive the same

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.Headers.Add(“Disposition-Notification-To”, “from@domainname.com”)
$msg.DeliveryNotificationOptions = “OnSuccess”
$msg.From = “from@domainname.com”
$msg.To.Add(”to@domainname.com”)
$msg.Subject = “Make the Delivery Recipt Work Please”
$msg.Body = “In a perfect world this email will generate a delivery receipt”
$msg.Attachments.Add($att)
$smtp.Send($msg)

Powershell script to send mail

Below Powershell script can be used to send mail using SMTP server. It reads every line from the text file and adds to the body of the email and sent it.

  $emailFrom = “Fromaddress”
 $emailTo = “Toaddress”
 $sub = Date
 $subject = “Subject ” + $sub
 $UserList = Get-Content “C:\Details.txt”
 $body = “”
 foreach($user in $UserList)
  {
     $body = $body + $user + “`n” # ‘n represents the new line escape sequence
  }
 $smtpServer = “SMTPServer”
 $smtp = new-object Net.Mail.SmtpClient($smtpServer)
 $smtp.Send($emailFrom, $emailTo, $subject, $body)

VBSCript to Send mail using CDO with Delivery and Read Recipient enabled

Below is the Procedure to send mail using CDO with Delivery and Read Recipient Enabled
Sub TestmailusingCDO_SMTP()
set objMsg = CreateObject(“CDO.Message”)
set objConf = CreateObject(“CDO.Configuration”)
Set objFlds = objConf.Fields
 
 With objFlds
  .Item(“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2
  .Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “SMTPServername”
  .Update ‘ Save
 End With

strBody = “This is a Test email.” & vbCRLF & vbCRLF & “—————————”

 With objMsg
  Set .Configuration = objConf
  .To = “<valid email addres>”
  .From = “<valid email addres>”
  .Subject = “Testing Email ” & Date()
  .TextBody = strBody ‘ Use .HTMLBody to send a HTML e-mail
  .Fields(“urn:schemas:mailheader:disposition-notification-to”) = “<valid email addres>”
  .Fields(“urn:schemas:mailheader:return-receipt-to”) = “<valid email addres>”
  .DSNOptions = cdoDSNSuccessFailOrDelay
  .Fields.update ‘ Save
  .Send
 End With

 

End Sub