Solved

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

Posted on 2015-01-16
10
176 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
A brief introduction to what I consider to be the best editor for PowerShell.
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…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

863 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

21 Experts available now in Live!

Get 1:1 Help Now