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
Solved

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

Posted on 2015-01-16
10
182 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 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

828 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