0

I've been trying to get this to work for a while now, and so far I've found lots of people saying it's a bug or it's a feature etc. But no-one really seems to have come up with a solution.

I've started using powershell (v2 admittedly, although I never had this problem with VBS, or any other language I've worked with) and when I send an email e.g. :

Send-mailmessage -to "[email protected]" -from "[email protected]" -subject "theSubject"

what I get back in place of my subject is:

=?us-ascii?Q?theSubject?=

What is this and why does powershell do it? It means that none of our in house applications accept email input from powershell at present.

I've tried -Encoding ([System.Text.Encoding]::ASCII), that made no difference.

Can anyone suggest a fix for this before I give up on powershell (which would be a shame because up until now I've been quite impressed).


EBGreen - My Actual code (taken straight from my script - names changed) is:

$cfg_Address = "[email protected]" $cfg_Subject = "emailTest" $cfg_FromAddress = "[email protected]" $cfg_SMTP = "123.12.1.12" Send-MailMessage -to "$cfg_Address" ` -From "$cfg_FromAddress" ` -Subject "$cfg_Subject" ` -SmtpServer "$cfg_SMTP" 

Matt - My EMail client is a custom built in house application that strips the internet headers and compares them to a set of rules to determine what to do. Looking at the same email in Outlook the subject is displayed correctly. But when I look at the headers it says:

Subject: =?us-ascii?Q?emailTest?= 

I ran a test and quickly mocked up the same email script using VBS (same To, From, Subject), and sent that to myself. Looking at the internet header for that one I get:

Subject: emailtest

9
  • -Encoding ([System.Text.Encoding]::ASCII) shouldn't make any difference since the default encoding is ASCII. Commented Oct 14, 2014 at 14:50
  • that's what I assumed, but it was suggested on various other sites Commented Oct 14, 2014 at 14:52
  • I dont know what your email client is. What is the encoding of the message when you receive it in your client? Commented Oct 14, 2014 at 15:28
  • Also, is the code you posted literally the code that you are running? Commented Oct 14, 2014 at 15:30
  • hi guys, see additions above. Commented Oct 15, 2014 at 8:31

2 Answers 2

1

It's a bug.

Powershell v2:

Date: Thu, 16 Oct 2014 18:29:21 +0300 Subject: =?us-ascii?Q?emailTest?= 

Powershell v4:

Date: Thu, 16 Oct 2014 18:27:33 +0300 Subject: emailTest 

Upgrade straight to WMF5 September Preview http://blogs.msdn.com/b/powershell/archive/2014/09/04/windows-management-framework-5-0-preview-september-2014-is-now-available.aspx or at least to PowerShell v4 (WMF4). The additional functionality you get is quite impressive.

Sign up to request clarification or add additional context in comments.

4 Comments

That's what I was afraid of. Looks I'm stuck with my Powershell/VBS combo until I can get all the servers upgraded.
According to this thread, there are a few ways around it. stackoverflow.com/questions/7482851/…
If all else fails, i've used this little bmail SMTP client for years and it's a solid performer all around. retired.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm
cheers, I looked at that thread previously, but the ideas mentioned either didn't work or generated various errors. So I abandoned it.
0

Whilst this isn't really an answer, it seems to be the best option that I can find.

1) Delete the Send-MailMessage entry from your script (as it seemingly doesn't work)

2) Create a separate file called SendEmail.vbs. In this file write a simple VBS Script to send the email. Place this alongside your powershell script.

3) In your powershell script add the line "$result = cscript "c:\path\to\script\SendEmail.vbs"

Now when when you run your powershell script it will use the VBS file to send the email.

Not ideal by any means, but at least it works.

2 Comments

I don't think there's any guarantee that this will work either. If the email is being correctly processed by Outlook, it's entirely possible that the problem isn't in how the message is sent but how the receiving application is processing it.
I've tested using Powershell, VBS, and PHP so far. And Both PHP and VBS send a 'correct' subject, only powershell sends the subject wrapped with additional characters. So as far as I can tell the problem is with powershell.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.