include B64.E
sequence afz,mailer
integer mailbody
function mailhead()
return mailer&"\nhelo ike\nmail from:<"&afz&">\n"
end function
function is_error(sequence filename)
integer error=0,file=open(filename,"r")
sequence text
if file>2
then text=gets(file)
while sequence(text) do
error=match("Error ",text)
if error then exit end if
text=gets(file)
end while
else error = -1
end if
return error
end function
global function Logon()
return 0
end function
global function Logoff()
return 0
end function
global function sendmail(sequence email_to;subject;line)
integer error=0,mailbody = open("mailbody","w")
if not mailbody
then error = -1
else
puts(mailbody,mailhead())
if atom(email_to[1]) then email_to = {email_to} end if
for i = 1 to length(email_to) do
puts(mailbody,"rcpt to:<"&email_to[i]&">\n")
end for
puts(mailbody,"data\nfrom:"&afz&"\nto:geadresseerde@alhier\n")
puts(mailbody,"Subject: "&subject&"\n")
puts(mailbody,line)
puts(mailbody,"\n.\n")
close(mailbody)
error = is_error("mbody.txt")
end if
return error
end function
global function sendfile(sequence email_to;subject;line;file_path)
constant my_boundery="simple_boundary"
integer filebody,error=0,mailbody = open("mailbody","w")
sequence text
if not mailbody
then error = -1
else
puts(mailbody,mailhead())
if atom(email_to[1]) then email_to = {email_to} end if
for i = 1 to length(email_to) do
puts(mailbody,"rcpt to:<"&email_to[i]&">\n")
end for
puts(mailbody,"data\nfrom:"&afz&"\nto:geadresseerde@alhier\n")
puts(mailbody,"Subject: "&subject&"\n")
puts(mailbody,"MIME-Version: 1.0\n")
puts(mailbody,"Content-Type: multipart/mixed; boundary=\""&my_boundery&"\"\n\n")
puts(mailbody,"--"&my_boundery&"\n")
puts(mailbody,"Content-Type: text/plain\n\n")
puts(mailbody,line)
puts(mailbody,"--"&my_boundery&"\n")
if length(file_path)
then if atom(file_path[1]) then file_path = {file_path} end if
for i= 1 to length(file_path) do
if i!=1 then puts(mailbody,"\n") end if
filebody = open(file_path[i],"rb")
if filebody>2
then
puts(mailbody,"Content-Type: application/octet-stream\n")
puts(mailbody,"Content-Transfer-Encoding: base64\n")
puts(mailbody,"Content-Disposition: attachment;filename=\""&file_path[i]&"\"\n\n")
text = get_bytes(filebody,57)
while sequence(text) and length(text)do
puts(mailbody,encode64(text)&'\n')
text=get_bytes(filebody,57)
end while
close(filebody)
puts(mailbody,"--"&my_boundery)
end if
end for
end if
puts(mailbody,"--\n")
puts(mailbody,".\n")
close(mailbody)
error = is_error("mbody.txt")
end if
return error
end function
mailbody = open("makemail.ini","r")
if mailbody>2
then afz=gets(mailbody)
mailer=gets(mailbody)
while sequence(mailer) do
if match("--",mailer)
then mailer=gets(mailbody)
else exit
end if
end while
close(mailbody)
afz = afz[1..-2]
mailer=mailer[1..-2]
else puts(1,"Error cann't open ini file\n")
abort(1)
end if