Solved

Powershell Send-mailmessage special characters

Posted on 2011-09-05
7
1,902 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
A short film showing how OnPage and Connectwise integration works.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

15 Experts available now in Live!

Get 1:1 Help Now