Here is a peared-down version of the function:
Best Regards
Jim
Code:
function smtpsendmail() as long smtphost$=bsmtp$ ''smtp server if smtphost$="" then txt$="No SMTP Host Entered - No Emails Will Be Sent" showtextmessage txt$ ''showtextmessage is like msgbox exit function end if ff&=freefile open "from.tmp" for binary as #ff& base=0 get$ #ff&,lof(ff&),b$ close #ff& fullemailfrom$=b$ stt&=instr(b$,"<") fin&=instr(b$,">") if stt&>0 and fin&>0 then lngth&=(fin&-stt&)+1 emailfrom$=mid$(b$,stt&,lngth&) elseif instr(b$,"@") then emailfrom$="<"+b$+">" else emailfrom$="" end if if emailfrom$="" or fullemailfrom$="" then showtextmessage "No 'From' Address Specified" exit function end if if dir$("from.tmp")<>"" then kill "from.tmp" ff&=freefile open "subject.tmp" for binary as #ff& base=0 get$ #ff&,lof(ff&),subject$ close #ff& if dir$("subject.tmp")<>"" then kill "subject.tmp" ''get addresses to send to if dir$("address.tmp")="" then showtextmessage "No Addresses Specified" exit function end if ''get all addresses to send to dim dta$(1:1) ff&=freefile open "address.tmp" for input as #ff& epeople&=0 while not eof(ff&) line input #ff&,ip$ b$=trim$(ip$) if b$<>"" then stt&=instr(b$,"<") fin&=instr(b$,">") if stt&>0 and fin&>0 then lngth&=(fin&-stt&)+1 emailto$=mid$(b$,stt&,lngth&) elseif instr(b$,"@") then emailto$="<"+b$+">" else emailto$="" end if if emailto$<>"" then incr epeople& redim preserve dta$(1:epeople&) dta$(epeople&)=emailto$ end if end if wend close #ff& if dir$("address.tmp")<>"" then kill "address.tmp" ''get message ff&=freefile open "message.tmp" for binary as #ff& base=0 get$ #ff&,lof(ff&),emessage$ close #ff& if dir$("message.tmp")<>"" then kill "message.tmp" ''create progress bar dialog createprogressbar hmess&,hed&,hprogress& settext hmess&,"Sending Email(s)" settext hed&,"Preparing To Send..." htcp&=freefile tcp open "smtp" at smtphost$ as htcp& e&=smtpgetline(htcp&,b$) if e&<>220 then destroywindow hmess& showtextmessage "Error Opening SMTP Host ("+trim$(str$(e&))+")" close htcp& exit function end if ''meet & greet the smtp host tcp print htcp&,"HELO "+smtphost$ e&=smtpgetline(htcp&,b$) if e&<>250 then destroywindow hmess& showtextmessage "Error Greeting SMTP Host ("+trim$(str$(e&))+")" close htcp& exit function end if oldprogbar&=0 on error goto smtperror for z&=1 to epeople& emailto$=dta$(z&) progbar&=(z&*100)/epeople& if progbar&<>oldprogbar& then oldprogbar&=progbar& settext hed&,"Sending: "+emailto$ setpositionprogressbar hprogress&,progbar& end if do tcp print htcp&,"MAIL FROM:"+emailfrom$ e&=smtpgetline(htcp&,b$) if e&<>250 then showtextmessage "Sender Address Error "+trim$(str$(e&))+" ("+emailfrom$+")" exit loop end if tcp print htcp&,"RCPT TO:"+emailto$ e&=smtpgetline(htcp&,b$) if e&<>250 then showtextmessage "Recipient Address Error "+trim$(str$(e&))+" ("+emailto$+")" exit loop end if tcp print htcp&,"DATA" e&=smtpgetline(htcp&,b$) if e&<>354 then showtextmessage "Data Error "+trim$(str$(e&))+" ("+emailto$+")" exit loop end if ''message header tcp print htcp&,"From: "+fullemailfrom$ tcp print htcp&,"Subject: "+subject$ ''this is the 1024 buffer code - I took it back out 'lmg&=len(emessage$) 'xstt&=1 'if lmg&>1024 then xfin&=1024 else xfin&=lmg& ' 'do until xstt&>lmg& ' lngth&=(xfin&-xstt&)+1 ' ip$=mid$(emessage$,xstt&,lngth&) ' lip$=left$(ip$,1) ' if lip$="." then ip$="."+ip$ ' tcp print htcp&,ip$; ' xstt&=xfin&+1 ' xfin&=xfin&+1024 ' if xfin&>lmg& then xfin&=lmg& 'loop 'tcp print htcp&," " ''all bytes at once ip$=left$(emessage$,1) if ip$="." then emessage$="."+emessage$ tcp print htcp&,emessage$ ''end of message tcp print htcp&,"." e&=smtpgetline(htcp&,b$) if e&<>250 then showtextmessage "Sending Email Message Error "+trim$(str$(e&))+" ("+emailto$+")" end if exit loop loop next z& setpositionprogressbar hprogress&,100 tcp print htcp&,"QUIT" e&=smtpgetline(htcp&,b$) destroywindow hmess& ''destroy progress dialog if e&<>221 then showtextmessage "Quit Error ("+trim$(str$(e&))+")" else e&=0 ''successful showtextmessage "Your emails were successfully sent" end if close htcp& redim dta$(1:1) function=e& exit function smtperror: e&=err close htcp& destroywindow hmess& showtextmessage "Undefined Error ("+trim$(str$(e&))+")" redim dta$(1:1) function=e& exit function end function function smtpgetline(byval htcp&,b$) as long if tcpgetline(htcp&,b$) then exit function else function=val(left$(b$,3)) b$=mid$(b$,5) end if end function
Jim Seekamp
Leave a comment: