muquit / mailsend

A program to send mail via SMTP from command line
Other
295 stars 68 forks source link

-msg-body not sending correctly #59

Closed Gregabyte closed 10 years ago

Gregabyte commented 10 years ago

I am trying to send an NT Backup log as the message body. The email that I receive contains 'ÿþB' instead of the log text.

This is the command I am using to send the log file: IF EXIST "%BackupLog%" C:\Tools\mailsend.exe -msg-body "%BackupLog%" -to logs@mynetwork.com -from support@mynetwork.com -name "NT Backup" -subject "NT Backup Log for %ComputerName% on %DateTime%" -smtp mail.mynetwork.com -port 465 -user support@mynetwork.com -pass 1234 -ssl -auth-login

This is the NT Backup Log:

Backup Status Operation: Backup Active backup destination: File Media name: "Backup-Mon.bkf created 6/30/2014 at 8:00 PM"

Volume shadow copy creation: Attempt 1. Backup of "MY-SRV\Microsoft Information Store\First Storage Group" Backup set #1 on media #1 Backup description: "Set created on 2014-06-30 Mon 20-00" Media name: "Backup-Mon.bkf created 6/30/2014 at 8:00 PM"

Backup Type: Normal

Backup started on 6/30/2014 at 8:00 PM. Backup completed on 6/30/2014 at 8:20 PM. Directories: 4 Files: 5 Bytes: 14,703,436,590 Time: 20 minutes and 13 seconds


Gregabyte commented 10 years ago

I am using version 1.17b15.

muquit commented 10 years ago

-msg-body can be used only for text or HTML, it includes the content as raw without any kind of encoding (#29). But character set can be specified. What is the format of NT backup log? Thanks.

Gregabyte commented 10 years ago

It is just a text file. I pasted the contents of the file above. I can send you a copy of the NT Log file if you'd like,

muquit commented 10 years ago

Yes please send me a sample file. Thanks.

Gregabyte commented 10 years ago

Lets see if this works.

On Wed, Jul 2, 2014 at 1:27 PM, muquit notifications@github.com wrote:

Yes please send me a sample file. Thanks.

— Reply to this email directly or view it on GitHub https://github.com/muquit/mailsend/issues/59#issuecomment-47815987.

 - Greg DeBoer
muquit commented 10 years ago

I don't think github Issues support arbitrary attachment types. Please mail it to me at muquit@gmail.com Thanks.

muquit commented 10 years ago

The file is in Unicode, hence the problem I guess. I've to play with it. I tried it with gmail and outlook, both seem to encode it as an attachment and does not display as text. Did you try it with any other mailer?

hex dump...

          0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f   0123456789abcdef
       0: ff fe 42 00 61 00 63 00 6b 00 75 00 70 00 20 00  ..B.a.c.k.u.p. .
      10: 53 00 74 00 61 00 74 00 75 00 73 00 0d 00 0a 00  S.t.a.t.u.s.....
      20: 4f 00 70 00 65 00 72 00 61 00 74 00 69 00 6f 00  O.p.e.r.a.t.i.o.
      30: 6e 00 3a 00 20 00 42 00 61 00 63 00 6b 00 75 00  n.:. .B.a.c.k.u.
      40: 70 00 0d 00 0a 00 41 00 63 00 74 00 69 00 76 00  p.....A.c.t.i.v.
....

Thanks.

Gregabyte commented 10 years ago

I was previously using blat & it was working just fine. (http://sourceforge.net/projects/blat/) The only issue with blat is that it can't send to SSL port like yours does. We have been finding out that our Internet Service Provider is now blocking port 25 traffic. I was able to send it as an attachment with the 1.16 but was hoping to send it as the message body instead of having to open it as an attachment. As far as I knew, it was just a basic text file.

muquit commented 10 years ago

It is a text file but not in US ASCII, that's why mailsend is having issue to include it as a body. However if you attach it as inline, it shows up as body in gmail and outlook, I think that's what you want. I only tested sending from linux at this time, I will test from Windows later. Here are the needed flags:

-cs "utf-8" -attach "NT.log.txt,text/plain,i"
muquit commented 10 years ago

I tested sending the log from Windows 7, attaching the file as inline, it works the way you were intending to work. The log shows up as mail body in gmail and outlook. Note: it is different than mailsend v1.16, v1.16 didn't have support for character sets. Try specifying the log as follows:

-cs "utf-8" -attach "NT backup.log,text/plain,i"

or you can specify mime parameters individually:

-cs "utf-8" -mime-type "text/plain" -disposition "inline" -attach "NT backup.log"

Please let us know how it works for you.

Thanks

Gregabyte commented 10 years ago

When I send the email, I got '��B' when I sent it using the first example. I got 'ÿþB' as the message body when I specified the mime in the second example.

muquit commented 10 years ago

Can you send the file to my gmail address using the both examples? I can not reproduce the problem. Thanks.

Gregabyte commented 10 years ago

I ran my batch file & had it send them to you with both examples. I also emailed you the log file I was trying to send.

muquit commented 10 years ago

Both test mails show the file as body.. screenshot attached. What mail reader you're using? Thanks.

On Wed, Jul 9, 2014 at 4:32 PM, Greg DeBoer notifications@github.com wrote:

I ran my batch file & had it send them to you with both examples. I also emailed you the log file I was trying to send.

— Reply to this email directly or view it on GitHub https://github.com/muquit/mailsend/issues/59#issuecomment-48530141.

http://www.muquit.com/

Gregabyte commented 10 years ago

I am using Office Professional Plus 2010 for my email. I sent it to my Gmail account & it showed up correctly. I sent you a copy of the emails I receive when I sent it to a work email account. Looks like some strange issue with our email server.

muquit commented 10 years ago

The files in the copy of emails to your work email account are plain ASCII. Something (may be your mailer or SMTP server converted it from UNICODE) and that's why it can be embedded in mail body as txt. There are lot of SMTP servers will not allow non ASCII characters in mail. It is safe to attach non ASCII files so that they will be encoded (base64 for mailsend) and any SMTP server will accept them. However if the UNICODE file is converted to ASCII, it can be included with -msg-body with mailsend. In Linux, the file can be converted to ASCII as follows:

iconv -f UNICODE -t ASCII  "NT.log_unicode.txt" > NT.log_ascii.txt

Thanks.

Gregabyte commented 10 years ago

What I ended up doing is running the command 'type NT.log > MSG.log' and sending the MSG.log. The 'type' converts it to ASCII for me.