Solved

Powershell Send-mailmessage special characters

Posted on 2011-09-05
7
1,891 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A procedure for exporting installed hotfix details of remote computers using powershell
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

14 Experts available now in Live!

Get 1:1 Help Now