Solved

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

Posted on 2015-01-16
10
167 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
  • 7
  • 3
10 Comments
 
LVL 68

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 68

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
 
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
The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

 
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 68

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

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now