powershell - send-mailmessage to send different attachments to different recipients -
Each of them needs to send email to thousands of different recipients with a different attachment. I have a text file with recipients The list and the other text file contains the list of attachment paths. For the first recipient in the text file, the first attachment path must be used. For the second recipient in the text file, the second attachment path should be used.
The code below sends all recipients to all recipients separately. But I want to do this as I mentioned above, only one email should be sent to each recipient with the respective recipient.
Please tell me whether it is worth achieving. I can also copy recipients and paths for attachment in two different columns of Excel spreadsheet if possible with Excel
I create thousands of separate mail-message lines with Excel I can achieve it, but it looks like an ugly way of doing this. This is the reason why I would like to know what is the best way to do this.
$ attachments = get content C: \ attach.txt $ recipients = get-content C: \ attachment) {foreign recipient ($ recipients) $ Recipient) {Send-MailMessage- "recipient@target.com") - Recipient recipient-topic "test" -smtpServer smtp.server.com -attachments $ attachment}}
a possibility:
$ MailParams = @ {from = "Recipient@target.com" topic = " Test "SmtpServer = 'smtp.server.com'} $ recipients = get-content C: \ Recip.txt get-contentC: \ attach.txt | Forex Currency {$ i = 0} {$ _ | Send-MailMessage @ MailParam- $ recipients [$ i ++]}
Comments
Post a Comment