Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell Send-mailmessage special characters

Posted on 2011-09-05
7
Medium Priority
?
1,982 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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

810 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