Solved

Powershell Send-mailmessage special characters

Posted on 2011-09-05
7
1,909 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
A brief introduction to what I consider to be the best editor for PowerShell.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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