OpenVMS Source Code Demos

BASIC_VMS_MAIL_SEND_DEMO.BAS

1000    %title "VMS_MAIL_SEND_DEMO"
	%ident "Version 100.1"
	!====================================================================================================
	! title  : VMS_MAIL_SEND_DEMO_100.bas
	! author : Neil Rieck (https://neilrieck.net) (mailto:n.rieck@bell.net)
	! created: 2009.06.19
	!====================================================================================================
	option type=explicit							! no kid stuff
        set no prompt								!
	!
	!	fetch a few declarations from the OpenVMS system library
	!
	%include "lib$routines"  %from %library "sys$library:basic$starlet"	! lib$
	%include "mail$routines" %from %library "sys$library:basic$starlet"	! mail$
	%include "$maildef"      %from %library "sys$library:basic$starlet"	! mail$_user_
	!
	!	declare a data structure to be used with MAIL$ calls
	!
	record ItemRec								! structure of item record
	    variant								!
		case								!
		    group one							!
			word	BuffLen						!
			word	ItemCode					!
			long	BuffAddr					!
			long	RtnLenAdr					!
		    end group one						!
		case								!
		    group two							!
			long	List_Terminator					!
			long	Junk1						!
			long	Junk2						!
		    end group two						!
	    end variant								!
	end record ItemRec							!
	!
	!	use the new data structure to declare some variables
	!
	declare itemRec list0(7)						! list supports items 0-7
	declare itemRec list1(7)						! list supports items 0-7
	declare itemRec list2(7)						! list supports items 0-7
	declare itemRec list3(7)						! list supports items 0-7
	!
	map(xyz)string	mail_to		= 255				,	&
		long	mail_to_L					,	&
		string	mail_from	= 255				,	&
		long	mail_from_L					,	&
		string	mail_subj	= 255				,	&
		long	mail_subj_L					,	&
		string	mail_body	= 255				,	&
		long	mail_body_L				
	!
	declare long	send_context%					,	&
			rc%						,	&
			handler_error%					,	&
			send_count%					,	&
			junk%						,	&
		string	junk$						,	&
			to$						,	&
			from$						,	&
			subj$						,	&
			body$						,	&
			distrib$
	!-----------------------------------------------------------------------
	!	send out some mail
	!-----------------------------------------------------------------------
	main:
	print "program: VMS_MAIL_SEND_DEMO"
	send_count%			= 0					!
	!
	to$				= "Neil"				!
	from$				= "CatBert@Dilbert.com"			! we can't do this from DCL
	subj$				= "Neil's Send VMS Mail Hack"		!
	body$				= "VMS_MAIL_SEND_DEMO_100.BAS"		! our source file
	distrib$			= ""					!
	gosub	send_mail							!
	!
	to$				= "neil.rieck@bell.ca"			!
	gosub	send_mail							!
	!
	distrib$			= "@CSMIS$ROOT1:[LISTS]DEMO_LIST.DIS"	! change this as required
	distrib$ = edit$(distrib$,2)						! no white space
	distrib$ = right$(distrib$,2)	if left$(distrib$,1) = "@"		!
	when error in
	    open distrib$ for input as #9					&
		,access read		! reduce potential lock conflicks	&
		,allow modify		! reduce potential lock conflicks	&
		,recordsize 255		! prevent line breaks at column 80
	    while 1								!
		linput #9, junk$						!
		junk$ = edit$(junk$,2)						! no white-space
		junk% = pos(junk$,"!",1)					! locate the first exclamation
		if junk% > 0 then						! if one was found...
		    junk$ = left$(junk$,junk%-1)				! ...only keep test up to it
		end if								!
		iterate if junk$ = ""						!
		to$			= junk$					!
		gosub   send_mail						!
	    next								!
	use									!
	    handler_error% = err						!
	    close #9								!
	end when								!
	select handler_error%							!
	    case 11								!
	    case else
		print "-e- error: "+ str$(handler_error%) +" while read file: "+ distrib$
	end select
	!
	goto nomore								!
	!-----------------------------------------------------------------------
	!	send vms mail
	!-----------------------------------------------------------------------
	send_mail:
	!
	rc% = MAIL$SEND_BEGIN(send_context%,0,0)				!
	print "MAIL$SEND_BEGIN error: ";rc%	if ((rc% and 7%) <> 1%)		!
	!
	!	destination stuff
	!
	mail_to				= to$					!
	mail_to_L			= len(to$)				!
	list0(0)::BuffLen		= mail_to_L				!
	list0(0)::ItemCode		= MAIL$_SEND_USERNAME			!
	list0(0)::BuffAddr		= loc(mail_to)				!
	list0(0)::RtnLenAdr		= 0					! n/a
	list0(1)::List_Terminator	= 0					! no more items in this list
	rc% = mail$send_add_address(send_context%, list0(0), 0)			!
	print "mail$send_add_address error: ";rc%	if ((rc% and 7%) <> 1%)	!
	!
	!	mail header stuff
	!
	mail_to				= to$					!
	mail_to_L			= len(to$)				!
	mail_from			= from$					!
	mail_from_L			= len(from$)				!
	mail_subj			= subj$					!
	mail_subj_L			= len(subj$)				!
	!
	list1(0)::BuffLen		= mail_to_L				!
	list1(0)::ItemCode		= MAIL$_SEND_TO_LINE			!
	list1(0)::BuffAddr		= loc(mail_to)				!
	list1(0)::RtnLenAdr		= 0					! n/a
	!
	list1(1)::BuffLen		= mail_subj_L				!
	list1(1)::ItemCode		= MAIL$_SEND_SUBJECT			!
	list1(1)::BuffAddr		= loc(mail_subj)			!
	list1(1)::RtnLenAdr		= 0					! n/a
	!
	list1(2)::BuffLen		= mail_from_L				!
	list1(2)::ItemCode		= MAIL$_SEND_FROM_LINE			!
	list1(2)::BuffAddr		= loc(mail_from)			!
	list1(2)::RtnLenAdr		= 0					! n/a
	!
	list1(3)::List_Terminator	= 0					! no more items in this list
	!
	rc% = mail$send_add_attribute(send_context%, list1(0), 0)		!
	print "mail$send_add_attribute error: ";rc%	if ((rc% and 7%) <> 1%)	!
	!
	!	body stuff
	!
	mail_body			= body$					!
	mail_body_L			= len(body$)				!
	list2(0)::BuffLen		= mail_body_L				!
	list2(0)::ItemCode		= MAIL$_SEND_FILENAME			!
	list2(0)::BuffAddr		= loc(mail_body)			!
	list2(0)::RtnLenAdr		= 0					! n/a
	list2(1)::List_Terminator	= 0					! no more items in this list
	rc% = mail$send_add_bodypart(send_context%, list2(0), 0)		!
	print "mail$send_add_bodypart error: ";rc%	if ((rc% and 7%) <> 1%)	!
	!
	rc% = mail$send_message(send_context%, 0, 0)				!
	print "mail$send_message error: ";rc%		if ((rc% and 7%) <> 1%)	!
	!
	!	release mail$send resources and context
	!
	send_count% = send_count% + 1
	print "-i-sending message: "+ str$(send_count%) +" to: "+ to$
	rc% = MAIL$SEND_END(send_context%,0,0)					!
	print "MAIL$SEND_END error: ";rc%  if ((rc% and 7%) <> 1%)		!
	!
	return									!
	!-----------------------------------------------------------------------
	!	that's all folks
	!-----------------------------------------------------------------------
	nomore:
	print "-i-total messages sent: "+ str$(send_count%)			!
	print "Adios..."							!
	end									!

Back to Home
Neil Rieck
Waterloo, Ontario, Canada.