Advertisement
Techguy95

Bulk email

Feb 6th, 2024
1,864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.63 KB | Source Code | 0 0
  1. # Define the email parameters
  2. $smtpServer = "smtp.office365.com"
  3. $smtpPort = 587 # adjust the port if necessary
  4. $from = "Mymail@something.dk"
  5. $attachmentPath = "C:\Users\xxx\Documents\ab421.pdf"
  6.  
  7. # Define SMTP credentials
  8. $username = "something"
  9. $password = "something" | ConvertTo-SecureString -AsPlainText -Force
  10. $credential = New-Object System.Management.Automation.PSCredential($username, $password)
  11.  
  12. # Define the body of the email (you can customize this)
  13. $body = @"
  14. Dear COMPANY_NAME,
  15.  
  16. I am writing to express my interest in [mention your purpose or reason].
  17.  
  18. Please find attached my resume for your consideration.
  19.  
  20. Thank you for your time.
  21.  
  22. Sincerely,
  23. Your Name
  24. "@
  25.  
  26. # Define the list of companies and their email addresses
  27. $companies = @(
  28.     @{
  29.         Name = "Trucks Company"
  30.         Email = "example@gmail.com"
  31.     }
  32.     # Add more companies as needed
  33. )
  34.  
  35. # Loop through each company
  36. foreach ($company in $companies) {
  37.     $to = $company.Email
  38.     $subject = "Unsolicited Application"
  39.     $bodyWithCompany = $body -replace "COMPANY_NAME", $company.Name
  40.  
  41.     # Create the mail message
  42.     $mailMessage = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $bodyWithCompany
  43.  
  44.     # Attach the file
  45.     $attachment = New-Object System.Net.Mail.Attachment($attachmentPath)
  46.     $mailMessage.Attachments.Add($attachment)
  47.  
  48.     # Create SMTP client
  49.     $smtp = New-Object Net.Mail.SmtpClient($smtpServer, $smtpPort)
  50.     $smtp.EnableSsl = $true
  51.  
  52.     # Send the email
  53.     $smtp.Send($mailMessage)
  54.  
  55.     # Dispose of the attachment
  56.     $attachment.Dispose()
  57. }
  58.  
  59. Write-Host "Bulk emails sent successfully."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement