Jump to content

Sending e-mail from command line?


Recommended Posts

Hello everybody,

I am trying to send an e-mail without using outlook, I use command lines. The thing is I am new to this and I don't know how to send an e-mail. I can compose one like this:

START mailto:test@test.com?subject=subject^&body=text

One can use this statement in a .bat-file, for example:

@echo off
START mailto:test@test.com?subject=subject^&body=text

I hope somebody can help me??

I know there are commercial software who can handle the job, but I want to do it myself or freeware...

Thanks in advance!

Remco

Link to comment
Share on other sites

  • 2 months later...

  • 7 months later...

Funny I read this thread and had a nother browser window/tab open to that very same topic I stumbled upon earlier this evening/morning...

Check out this thread How do I send e-mail from KiXtart? (SMTP) .

Before you say... but I said the COMMAND LINE.... Note they mention several techniques, including Blat

I've never used either one, so I can't help you beyond directing you to that post and site.

(edit) Just re-read your post. Did you want to open up a new message so the user can type stuff before sending, or did you just want to send a message via the command line with no user interaction?

Edited by JoeMSFN
Link to comment
Share on other sites

I got two scripts for this purposes:

First one is using actual Outlook configuration

Option Explicit

Dim objOutlook, objNameSpace, objMail
Dim strAddress, strSubject, strBody, strMailItem

strAddress = "martin.zugec@gmail.com"
strSubject = "Test"
strBody = "Automating send test"

Set objOutlook = WScript.CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.getNamespace("MAPI")
Set objMail = objOutlook.CreateItem(strMailItem)

objMail.Subject = strSubject
objMail.Body = strBody
objMail.RecipIents.Add(strAddress)
objMail.Send

SET objOutlook = nothing
SET objNameSpace = nothing
SET objMail = nothing

Second one is using SMTP, so it is Outlook-independent.

Option Explicit

Dim objEmail, objNetwork
Dim strComputerName

Set objEmail = CreateObject("CDO.Message")
Set objNetwork = CreateObject("Wscript.Network")

strComputerName = objNetwork.ComputerName

With objEmail
  .From =  strComputerName & "@domain.com"
  .To = "martin.zugec@gmail.com"
  .Subject = "Test"
  .Textbody = "Testing mail delivery"
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "pred-hub.pre.cz"
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  .Configuration.Fields.Update
  .Send
End With

Set objEmail = Nothing
Set objNetwork = Nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...