Solved

How can I use Exchange Powershell to send an email in different languages?

Posted on 2015-01-16
10
186 Views
Last Modified: 2015-01-27
I have a Powershell script that sends an email to a list of email addresses located in a input file.  But, some of these users need to receive the email in another language other than English.  The input file will have a language code as well.  But, I need help modifying my script to send multiple emails in different languages.  FYI - the body and subject of the email will be static.   Thanks so much for the help!

Here is the script:


Start-Transcript -PATH UserImportLog.txt -append


#Importing the input file with three variables (Name,emailaddress,languagecode)

$Data = Import-Csv -Path UserImport.csv
$Data | foreach-object {

     $PSEmailServer = "smtpserver"
     
     Send-MailMessage -From "test.user@domain.com" -To $_.emailaddress -Subject "Test email" -Body "this is a test"

     }

Stop-Transcript
0
Comment
Question by:bcapello
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40554483
Start-Transcript -PATH UserImportLog.txt -append

# Language specific text
$msg = @{
  en = 'This is a test'
  de = 'Das ist ein Test'
  nl = 'kann nit verstaan'
}

#Importing the input file with three variables (Name,emailaddress,languagecode)

Import-Csv -Path UserImport.csv | foreach-object {      
     Send-MailMessage -SmtpServer smptserver -From "test.user@domain.com" -To $_.emailaddress -Subject "Test email" -Body $msg[$_.languagecode]
}

Stop-Transcript

Open in new window

if we can assume languagecode to be e.g. en for English.
0
 
LVL 5

Author Comment

by:bcapello
ID: 40554508
Got an error:

Index operation failed; the array index evaluated to null.
At C:\Users\capbr01adm\Desktop\INIT-Approvals.ps1:25 char:132
+      Send-MailMessage -SmtpServer servername -From "username@domain.com" -To $_.emailaddress -Subject "Test emai
l" -Body $msg[ <<<< $_.languagecode]
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Users\capbr01adm\Desktop\INIT-Approvals.ps1:25 char:132
+      Send-MailMessage -SmtpServer servername -From "username@domain.com" -To $_.emailaddress -Subject "Test emai
l" -Body $msg[ <<<< $_.languagecode]
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40554518
Check the languagecode of the CSV file. There is no error checking, so it needs to be populated.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 5

Author Comment

by:bcapello
ID: 40554803
Ok. I'll double check it tomorrow morning. I thought I tested it with one 'en' and one 'de'.
0
 
LVL 5

Author Comment

by:bcapello
ID: 40555045
All set. Thanks for the help!
0
 
LVL 5

Author Comment

by:bcapello
ID: 40573196
Any chance you can give me a hand embedding 2 images in the email?
0
 
LVL 5

Author Comment

by:bcapello
ID: 40573208
Here is what I have so far.  I'd like to embed an image at header of the email and a different image at the footer.

Start-Transcript -PATH UserImportLog.txt -append

# Language specific text
$Subject = @{
  en = @"
Service Request Approval
"@
  fr = @"
Approbation d’une demande de service
"@
}
$msg = @{
  en = @"

HTML Message
"@

}

#Importing the input file with two variables (emailaddress,languagecode)

Import-Csv -Path UserImport.csv | foreach-object {
     
 
     Send-MailMessage -SmtpServer [servername] -From "smtpaddress" -To $_.emailaddress -BodyasHTML -subject $subject[$_.languagecode] -Body $msg[$_.languagecode] -Encoding ([System.Text.Encoding]::UTF8)
}

Stop-Transcript
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40573246
It depends. You can add them as attachments. Anything different requires to have inline images or pictures available via public link, and I cannot help with that, because that is a HTML topic.
0
 
LVL 5

Author Comment

by:bcapello
ID: 40573258
I wonder if adding them as inline attachments will force Outlook to download them and display them in the email?
0
 
LVL 5

Author Comment

by:bcapello
ID: 40573286
I just figured it out! Thanks for the help. once again!
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read this checklist to learn more about the 15 things you should never include in an email signature.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question