Advertisement
Techguy95

Bulk email

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