Solved

Powershell Send-mailmessage special characters

Posted on 2011-09-05
7
1,925 Views
Last Modified: 2012-05-12
I am trying to use Powershell Send-mailmessage.


When I use ¤ (fx. ¤test@test.com) in the to string it fails with:

Send-MailMessage : A recipient must be specified.
At C:\tha\Untitled1.ps1:11 char:18
+  send-mailmessage <<<<  -To $EmailTo -From $EmailFrom -Subject $EmailSub -Body $EmailBody -Att
achment $EmailAtt -SmtpServer $EmailSmtp
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-M
   ailMessage], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.SendMailM
   essage


If I remove ¤ from the to string it works fine.


How do I get this to work?
0
Comment
Question by:ThomasAlbaek
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 4

Expert Comment

by:Daelt
ID: 36483206
did you try with some " " ?
0
 

Author Comment

by:ThomasAlbaek
ID: 36483216
I am trying this

[string[]]$EmailTo = "¤test@test.com"

send-mailmessage -To $EmailTo -From $EmailFrom -Subject $EmailSub -Body $EmailBody -Attachment $EmailAtt -SmtpServer $EmailSmtp
0
 
LVL 4

Expert Comment

by:Daelt
ID: 36483301
never tried with that kind of character but if normal quote doesnt work, try with this :

[string[]]$EmailTo = "\¤test@test.com"

the \ before the character should echo the character normally without having shell trying to work with it.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 49

Expert Comment

by:Akhater
ID: 36483764
where are you running this test? i tried it on windows 2008R2 and I have no problem with the *  however I have an issue with the [string[]] part since it cannot convert a string array to string.



$from ="*a@a.com"

send-mailmessage -from $from -to "*a@b.com" -subject "whatever" -body "Just a test." -smtpServer localhost

this worked fine for me

also test adding <> something like $to = "<*test@test.com>"
0
 
LVL 4

Accepted Solution

by:
krf1963 earned 250 total points
ID: 36484656
Why do you want the '¤' character in the e-mail address? I'm pretty sure it's not RFC compliant, and I would not expect it to work. When I try it I get the same message as you, but before it I get:

Send-MailMessage : The specified string is not in the form required for an e-mail address.
At line:1 char:17
+ send-mailmessage <<<<  -to $recip -from "test1@domain.com" -subject "Test" -body "Test" -smtpserver smtpserver
    + CategoryInfo          : InvalidType: (:) [Send-MailMessage], FormatException
    + FullyQualifiedErrorId : FormatException,Microsoft.PowerShell.Commands.SendMailMessage
0
 
LVL 49

Expert Comment

by:Akhater
ID: 36484706
wait a sec I might have read it wrong, are you talking about * or ¤ ???


a * is RFC complient and my test was successful, if you are talking about a ¤ then krf1963 is right and it is not a legal character
0
 

Author Closing Comment

by:ThomasAlbaek
ID: 36486744
@krf1963
You are right, ¤ Will not work. I changed it to a valid character and that works.
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 will help you understand what HashTables are and how to use them in PowerShell.
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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