help email

Title

psemail -- Send Emails through Stata's do file or via Stata's command line.

Syntax

psemail toAddress,
[options]

s(subject) Subject line

b(Email body) The body of your email.

a(attachment) Attachement file, better with a folder path. If there are blanks in the file name of path, please use double quoates

p(n|h|l) privority leve, can be h, l and normal. the default is set to be normall

toAddress is the receipt's email address.

The program will first check whether there is an "@" and there are ".", but cannot fully check if the email address is valid.

The body of the email can be of multiple lines. when input the body sentences, carriage return is replaced by `r`n

Suppose you are going to use the following three lines as email body

Hello World!

Stata can send Emails now.

Really interesting!

You need to set the body option as following

b(Hello World!`r`n Stata can send Emails now.`r`n Really interesting!)

Example1

. clear

. set obs 100

. gen x = uniform()

. save d:\temp, replace

. save "d:\temp 1.dta", replace

. psemail chuntao@baf.cuhk.edu.hk, s(test mail 1) b(Hello! World!)

. sleep 3000

. psemail chuntao@baf.cuhk.edu.hk, s(test mail 2) b(Hello! World!) a(d:\temp.dta)

. sleep 3000

. psemail chuntao@baf.cuhk.edu.hk, s(test mail 3) b(Hello! World!) a("d:\temp 1.dta")

. sleep 3000

. psemail chuntao@baf.cuhk.edu.hk, s(test mail 4) b(Hello World!`r`n Stata can send Emails now.`r`n rather funny!) a("d:\temp 1.dta")

. sleep 3000

Example2

Suppose you have a list of students name, email address and test score.

Those information are stored in d:\student.dta with three variables as name, email and testscore

Suppose you want to send each student an email to let them know their own test score.

A program can be as following.

. use d:\student, clear

. local N=_N

. forval i =1(1) `N' {

. local name = name[`i']

. local email = email[`i']

. local testscore = testscore[`i']

. psemail `email', s(test score) b(Dear `name' `r`n Your recent test score for mathematics is `test score'. `r`n Best, `r`n Dr. Tony Lee )

. sleep 3000

. }

Important Note 1

To install this command, the user have to configer your own stata so that stata knows your email information.

The user need to change his/her profile.do, normally stored at the default ado directory or personal directory.

help sysdir for more information.

After configeration, Suppose you are using a gmail as your own email, and your account is youremail@gmail.com.

Your profile.do should have the following lines.

global EmailFrom youremail@gmail.com

global EmailAccount youremail

global EmailPassword yourpassward

global EmailSmtpServer smtp.gmail.com

global EmailSmtpPort 587

global EmailSender "Yourname"

Important Note 2

Every time we send an email with email.ado, Stata fires up your powershell

We use stata to design a powershell .ps1 file

When the powershell is fire up, it will run the Stata designed .ps1 file

Since it always takes time to fire up and to close the powershell, we recommand the user to stop the Stata program 3 seconds

everytime you send an email.

suppose your email address is mygmail@gmailcom.

The following code will probably send the same email because Stata runs far more faster than powershell's fire up and closing procedure

. forval i =1(1) 3 {

. psemail mygmail@gmailcom, s(Test Email`i')

. }

Add a line to stop Stata for 3 second, you will get your desiable results

. forval i =1(1) 3 {

. psemail mygmail@gmailcom, s(Test Email`i')

. sleep 3000

. }

Authors

Xuan Zhang

Zhongnan University of Economics and Law

Wuhan, China

zhangx@znufe.edu.cn

Dongliang Cui

North East University

Shenyang, China

cuidongliang@mail.neu.edu.cn

Chuntao Li

Zhongnan University of Economics and Law

Wuhan, China

chtl@znufe.edu.cn