Giter Site home page Giter Site logo

Comments (18)

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024 1

So I just did some testing:

image

image

So it seems to work. I've not tested it with old version but after upgrading to 3.1.0 which will be used in next release (hopefully).

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024 1

Added MimeMessagePath string which allows saving the message request if we ever need to troubleshoot it

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

@jstedfast Do you have any idea what would not be stripped by [MimeKit.BodyBuilder]::new() that we're using when it comes to new lines for text?

from mailozaurr.

jstedfast avatar jstedfast commented on August 25, 2024

I'm thinking that this may be more likely to be an issue with passing the body as a string on the command-line? I'm not sure, though.

Keep in mind that when sending a message, message bodies are ALWAYS formatted with DOS line endings (aka CRLF).

Is the body base64 encoded? That might cause issue if the input has LF instead of CRLF, but otherwise it shouldn't be an issue.

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

The -Raw switch definition:

Ignores newline characters and returns the entire contents of a file in one string with the newlines preserved. By default, newline characters in a file are used as delimiters to separate the input into an array of strings. This parameter was introduced in PowerShell 3.0.

That means it's one string with everything as is - so should be fine.

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

foo

^^ It's CRLF

from mailozaurr.

jstedfast avatar jstedfast commented on August 25, 2024

The BodyBuilder class just takes the TextBody and/or HtmlBody string property values and sets them as the Text property on a TextPart when it constructs the message body.

TextBody.Text calls SetText() which just does Encoding.UTF8.GetBytes(). There's no line-ending conversion.

Also note that SmtpClient.Send/Async() makes sure that line endings are CRLF format (mostly needed when running on Linux) since SMTP specifies line endings must be CRLF.

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

tb

In order to be sure I saved the email as TXT in Thunderbird. Send-MailMessage (upper) preserves the CRLF (and adds 3 more at the end?) compared to Send-EMaillMessage (lower) which converts it to a space (0x20)

from mailozaurr.

jstedfast avatar jstedfast commented on August 25, 2024

I can't think of anything in MimeKit/MailKit that would replace CRLF with a space.

Would it be possible to dump your message to a file (before sending via SMTP) so that we can see the raw message being sent before any other software has a chance to modify it?

Ideally it would use the MimeMessage.WriteTo() method.

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

I'm not a programmer and would need guidance on that.

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

Basically just about here:

$SmtpClient.Timeout = $Timeout

You would need to do:

$Message.WriteTo($PathToFile)

So you either modify the module a bit, reimport it with Import-Module -Force and try again or I guess we could add some sort of debug method to Mailozaurr.

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

Here's the code responsible for using BodyBuilder to build HTML/Text and then assign that Body to $Message.Body

$BodyBuilder = [MimeKit.BodyBuilder]::new()
if ($HTML) {
$BodyBuilder.HtmlBody = $HTML
}
if ($Text) {
$BodyBuilder.TextBody = $Text
}
if ($Attachment) {
foreach ($A in $Attachment) {
$null = $BodyBuilder.Attachments.Add($A)
}
}
$Message.Body = $BodyBuilder.ToMessageBody()

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

Looks promising - and sorry that I was not yet able to get the dump. During week time I hardly have time for such things and my plan was to deal with it on the upcoming Saturday. But now I wait for the next release.

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

@stethos give new version a try

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

image

Sorry, still not working for me in my email client (Outlook and Thunderbird)

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

what if you use the example, with the file i prepared that's on github?

from mailozaurr.

PrzemyslawKlys avatar PrzemyslawKlys commented on August 25, 2024

Ohhh, you're using body.... that's for HTML, you should use Text :-)

$Text = Get-Content -Path "$PSScriptRoot\Input\Test.txt" -Raw

# this is simple replacement (drag & drop to Send-MailMessage)
Send-EmailMessage -To '[email protected]' -Subject 'Test' -Text $Text -SmtpServer 'smtp.office365.com' -From '[email protected]' -Priority High -Credential $MailCredentials -UseSsl -Port 587 -Verbose

Text property takes text, body takes HTML. I am not able to distinguish between HTML and text in easy way, so I expose two options. Also you can provide both - so when HTML is disabled, text shows up AFYIK.

from mailozaurr.

stethos avatar stethos commented on August 25, 2024

Gosh, -Text works like a charm!

Did not think about this one as I just replaced the SendMailMessage by SendEMailMessage withoug digging more deeply into every parameter.

Thank you for all your help and time you have spend on that one.

from mailozaurr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.