Menu
Reply
  • 1
  • 0
  • 0
pfdsmyth
Just joined
406 Views
Message 1 of 7
Flag for a moderator

Command line email - mailrc config or windows alternate

I am trying to send email from a command line on a pc. These would be generated from batch files and scheduled tasks / cron.

I have done this lots before on linux computers, so it would be simplest to repeat on that platform, but I could migrate the batch files / tasks onto a Windows 10 pc if needs be.

I have a .mailrc that looks like this:

##########################################
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.virginmedia.com
set smtp-auth=Enabled
set smtp-auth-user=*******@virginmedia.com:465
set smtp-auth-password=mypassword
set smtp-ssl=Enabled
set from="*******@virginmedia.com"
##########################################

Ideally, I  send an email as follows:

cat test.txt | mailx -s "TEST_EMAIL_01" mygmail@gmail.com

I'm not getting anywhere. Earlier tests resulted in a failed 'send' test, suggesting I check this url:

https://support.google.com/mail/answer/10336?p=NotAuthorizedError&visit_id=0-636172295470309971-6096...

On the linux box, I can send/receive email from the VM webmail page, and from Thunderbird configured to my VM email details, so there are no fundamental comms issues.

I think I just need a better .mailrc configuration.

Has anyone done this successfully?

I'm happy to consider a 'Windows' option.

I'm gonna keep digging away at this, but if anyone gets back with a working solution before I get there, I'll be happy to reward your efforts.

Sincere regards

Paul

 

 

 

[MOD EDIT: Personal and private information has been removed from this post. Please do not post personal or private information in your public posts. Please review the Forum Guidelines]

0 Kudos
Reply
  • 13.63K
  • 719
  • 4.72K
Superuser
Superuser
398 Views
Message 2 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate

Well for one thing the following would not work on Port 465

set smtp-use-starttls

Port 465 uses implicit TLS where the first thing that happens is an SSL/ TLS connection is negotiated with the server from the outset.

StartTLS on the other hand  connects to the server first using plain text and then sends an EHLO, if the server sends back StartTLS in it's list of capabilities THEN it upgrades by sending a StartTLS command back to the server and negotiating an SSL/TLS connection.

Ravenstar68

________________________________________


Only use Helpful answer if your problems been solved.

0 Kudos
Reply
  • 1.42K
  • 154
  • 457
Superuser
Superuser
387 Views
Message 3 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate

Take a look at Microsoft PowerShell Utility - Send-MailMessage

0 Kudos
Reply
  • 13.63K
  • 719
  • 4.72K
Superuser
Superuser
381 Views
Message 4 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate

Which would be good except he's using linux

That's a bash script there I believe.

________________________________________


Only use Helpful answer if your problems been solved.

0 Kudos
Reply
  • 13.63K
  • 719
  • 4.72K
Superuser
Superuser
353 Views
Message 5 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate

This has just worked for me for blueyonder

set smtp-verify=ignore
set smtp=smtps://smtp.blueyonder.co.uk:465
set smtp-auth-user=my.address@blueyonder.co.uk
set smtp-auth-password=mypassword
set from=<my.address@blueyonder.co.uk>

Replace smtp.blueyonder.co.uk with smtp.virginmedia.com and it should work.

Ravenstar68

________________________________________


Only use Helpful answer if your problems been solved.

0 Kudos
Reply
  • 1.42K
  • 154
  • 457
Superuser
Superuser
347 Views
Message 6 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate


ravenstar68 wrote:

Which would be good except he's using linux

That's a bash script there I believe.


OP is open to Windows alternative. BTW, reportedly you can now run bash on Ubuntu on Windows and PowerShell is available on Linux.

  • 13.63K
  • 719
  • 4.72K
Superuser
Superuser
330 Views
Message 7 of 7
Flag for a moderator

Re: Command line email - mailrc config or windows alternate

Well the OP got me interested in mailx and I found that there are alternative packages one can install.

I'm using Ubuntu and I originally was using bsd-mailx, however I found heirloom-mailx is a much better package

bsd-mailx seems more tied into sending via postfix on localhost.  Unless I've missed something.  So it was working because I'd already configured postfix on my PC to relay my outbound mail via smtp.blueyonder.co.uk

heirloom-mailx on the other hand allows you to configure not only a default server but also per account servers.

Consider the following configuration in either etc/mail.rc or ~/.mailrc

	set smtp-auth=login
	set smtp=smtps://smtp.virginmedia.com:465
	set smtp-auth-user=address@virginmedia.com
	set smtp-auth-password=<virgin password>
	set from="address@virginmedia.com(Timmy)"
	set ssl-verify=warn

account blueyonder {
	set smtp-auth=plain
	set smtp=smtps://smtp.blueyonder.co.uk:465
	set smtp-auth-user=address@blueyonder.co.uk
	set smtp-auth-password=<blueyonder password>
	set from="address@blueyonder.co.uk(Tim)"
	set ssl-verify=warn
}

Note that if I send just mailx <destination address> Then the mail is sent via smtp.virginmedia.com

If on the other hand I send mailx -A blueyonder <destination address>

Then the mail is sent via my blueyonder address using smtp.blueyonder.co.uk - still on port 465

@用心棒 I think I owe you an apology though, I didn't see about the Windows solutions.

Ravenstar68

Edit - BTW both servers will accept smtp-auth=plain or smtp-auth=login  I was just playing with the configs, there's no need to have different mechanisms like I have.

 

________________________________________


Only use Helpful answer if your problems been solved.