?
Solved

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

Posted on 2015-01-16
10
Medium Priority
?
192 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 70

Accepted Solution

by:
Qlemo earned 2000 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 70

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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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 70

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 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