SendOneEmail failing to include recipient email address

I have some very simple code using SendOneEmail. In a new database, it has worked for the first 150 emails that I needed to send over a day or two. Now it is creating the email but the recipient’s email address is not getting carried over to the email in Mail. The email gets dumped into the Draft folder where I see the missing email address.

I’ve verified that the email address field that it is being pulled from is simple and accurate with no leading or trailing odd characters or returns, etc.

After the SendOneEmail started failing, I, in my haste of not having the time to debug it, rewrote the procedure to use SendEmail instead. All was good for a few dozen emails. Then, SendEmail started failing without the recipient’s email address!!!

What the heck? Ideas?

In other databases, I’ve used the SendOneEmail with attachments, etc, for thousands of email over many years.

I don’t know the answer to this. You don’t mention what channel you are using, but I surmise it must be Apple Mail. So maybe the problem is in Mail. Mail has changed a lot since this channel was written.

You also mentioned that you’ve used SendOneEmail with attachments, which really puzzles me, since SendOneEmail doesn’t support attachments. I seem to recall someone wrote a hacked version that did support attachments, but I don’t know anything about it. In fact, I did not write the Apple Mail channel, and have never used it (in fact, I don’t use Mail either), so I’m not very knowledgeable on this topic. But it doesn’t seem surprising that this more than decade old channel might have problems with the latest version of Mail. I do know that this channel depends on AppleScript, perhaps there is an authorization error that is preventing transfer of the email address.

Whether you’re using SendOneEmail or SendEmail, both are using the same channel. So it’s not surprising that the problem persists with that change. Sounds like the problem might be on the Mail end.

I’ll start with correcting that it is SendEmail that I use for attachments. This is being accomplished by a Channel written by David (of course).

I have continually used the channel to send over 88,000 emails so I know that works. :slight_smile: The typical database continues to work fine without a hiccup and has recently been used successfully but as Channels, AppleScript, and Mail are all involved, I’m not seeing an easy path to figure it out.

But the ‘new’ part of all this is that the problem surfaced in a recently created database. I’ll take responsibility for when something doesn’t run but when it works for 100 emails then starts to not work, that puzzles me. And then too, when I switched to a different Command and that worked for a few dozen, then started failing with the same odd problem, I was really stumped. I did verify that I am sending a real, correctly formatted email address to the emaill commands and it is passing the Subject, and the Body properly. It is just not the email address that is being inserted into the email that then ends in the Draft folder due to a lack of recipient.

I do notice that I can use SendArrayEmail and SendBulkEmail and see if I can sqeek out a few more hundred emails.

Of course all of this is a big rush attempting to contact thousands of customers immediately due to the Coronavirus. :frowning:

Just thought the whole thing was odd enough that someone might have an idea as to the cause. I get that this problem is with Classic and I get what I get. My problem. Just looking for an idea of what it might be.

Thanks for the reply.

Just guessing: If it works first and then starts to omit addresses, it seems the working components are getting “out of sync”; one component is too fast for the other. Perhaps you could make Panorama wait for some AppleScript result?

Another (nearly almighty) cure: What about a restart of your Mac? :grinning:

Created a new db.

Created procedure with SendEmail.

Sent out ~250 in batches of 40-50 over 2 days.

Then at a certain point in the db, the email in Mail only had empty recipients. I was too busy to debug.

Rewrote the procedure to use SendOneEmail. It immediately started working correctly from the las record that didn’t work with SendEmail. This worked for several batches of 40-50 records. Then at some point, only empy emails in Mail.

I will try the other Email commands in the procedure and see if they will work. Any of them can be used in this situation with minor tweaking in the procedure. I will update after trying other commands. A different command should not start working when a previous one should happen to break. That is the part that doesn’t make sense.

Yes, several restarts did not change anything. The speed of a Loop is slow enough that Mail gets behind only slightly but that only causes emails to sit in the Out box for a very short period of time and only when we send out hundreds in a batch which has not been any part of this scenario.

Is it possible you’re hitting a daily limit with your service provider? I can’t think of any reason why it would affect the recipient addresses but it would start generating an error within Mail. My service is limited to 250 emails every 24 hours unless I upgrade the account to allow more.

No. When that happens, the fully complete email gets created and it sits in the Outbox but we do get a message from the SMTP server with a very clear message telling us how many we’ve sent, how long it will be before the count is reset, etc.

FWIW: Yes, we too have a 250@day limit but we just create additional email accounts as they each get the 250 limit. ie Support2@ Support3@, Support4@, etc.

In this case, using a different Command starts it working again with the exact same SMTP settings, server, etc.

And the answer was…

Invisible characters that had crept in during the Import from QuickBooks. The invisibles were between the first character and the last character of the email text string!! Not where you would expect to find them. We did earlier recognize that there were invisibles at the beggining and the end but we figured that that was all about Tabs, CR, etc. To have found them within the email string was odd (to me.) Once filtered out, all is fine now.

Thanks for your time and thoughts.

I need to send emails with an attachment. In the past, I have used a custom statement “zemailwithattachments”. It works fine without an attachment, but when I add an attachment to the statement, it no longer sends. I may have the form for the attachment wrong, but I have guessed at several different variations without success.
Can anyone help with using zemailwithattachments or suggest another custom statement that can handle attachments?


I developed zemailwithattachments long ago in Panorama 6 by adding a front end to Dave’s excellent “Mail w attachments” channel code.

I’ve been using a modified version for some years, zemailattachments, which is enclosed. I can’t remember what I changed from zemailwithattachments (and don’t have time right now to check) but it is working fine for me every day in Panorama X and should solve your problem. It uses the same parameters as the original.

David Duncan

  This statement sends a single email to one or more recipients with attachments if specified. The statement has four parameters which can be in the form of constants or variables or formulas or a mixture of these. Attachments are deleted after emailing.

The procedure has four parameters. All can be in the form of constants or variables or a mixture of these.
"someone@someisp.url" e-mail address of recipient (may be repeated for multiple recipients)

"topic" (if missing use "no subject")

File name of attachment (may be repeated for multiple attachments). Must be on the desktop.
If attachments not required, leave parameter space empty


local eRecipients,eSubject,eAttachments,eOptions,lAttachmentName,lTrashFileList,

eRecipients=replace(replace(parameter(1)," ",""),","," ")
arrayfilter eRecipients,eRecipients," ","to="+import()
arrayfilter eAttachments,eAttachments,",","attachment={"+folderpath(info("desktopfolder"))+import() +"}"
eAttachments=replace(eAttachments,","," ") 

//[--Are attachment files available?--]
        If Y>10              //…takes about 35 seconds before giving up
            AlertOK "File '"+lAttachmentName+"' is not available on the Desktop, so it cannot be sent in an email" 
        If arraysearch(listfiles(info("DesktopFolder"),""),lAttachmentName,1,¶)=0     // is it on the Desktop yet?
            Superalert ||Waiting for output of ||+¶+||"||+lAttachmentName+||" to appear on the Desktop||, {height=130 width=260 buttons="OK" timeout="3"}
    Until arraysearch(listfiles(info("DesktopFolder"),""),lAttachmentName,1,¶)>0
Until X=extract(parameter(3),",",-1)

    eRecipients+" "+"subject={"+eSubject+"} "+eAttachments

//displaydata eOptions
/*    This section actually sends the e-mail.  The procedure has two parameters:
    This parameter must contain assignments for various e-mail options, including
    the recipient, sender, subject, server, etc. 
        smtp="mail.myisp.url" address of SMTP server (optional, if missing use default value)
        From="x@xx.url" e-mail address of sender (optional, if missing using default value)
        FromName="My Name" name of sender (optional, if missing use default value, if any)
        To="someone@someisp.url" e-mail address of recipient (may be repeated for multiple recipients)
        cc="someone@someisp.url" e-mail address of carbon copy recipient (may be repeated for multiple recipients)
        bcc="someone@someisp.url" e-mail address of blind carbon copy recipient (may be repeated for multiple recipients)
        Subject="topic" (if missing use "no subject")
        Attachment="Full:Path:and:File Name" full path and file name of attachment (may be repeated for multiple attachments)
        errormessage=on/off/yes/no/true/false - if on/yes/true display error message if problem and stop, otherwise
            place error message in global variable ChannelResult. If ChannelResult match "Sent*" then e-mail was sent ok.


eTo=tagparameterarray( eOptions, "to=" , ¶ )
if eTo <> ""
    ArrayFilter eTo,eTo,¶,“make new to recipient at end of to recipients with properties {address:”+applescriptstring(array(eTo,seq(),¶))+“}”

eCC=tagparameterarray( eOptions, "cc=" , ¶ )
if eCC <> ""
    ArrayFilter eCC,eCC,¶,“make new cc recipient at end of cc recipients with properties {address:”+applescriptstring(array(eCC,seq(),¶))+“}”

eBCC=tagparameterarray( eOptions, "bcc=" , ¶ )
if eBCC <> ""
    ArrayFilter eBCC,eBCC,¶,“make new bcc recipient at end of bcc recipients with properties {address:”+applescriptstring(array(eBCC,seq(),¶))+“}”

if eSubject=""
    eSubject="(no subject)"

eAttachments=tagparameterarray( eOptions, "attachment=" , ¶ )

if eAttachments <> ""
    ArrayFilter eAttachments,eAttachments,¶,applescriptstring(import())
    eAttachments="{"+replace(eAttachments,¶,", ")+"}"
    eListAttachments=“set theAttachments to ” + eAttachments + “
    set theseFiles to {}
    repeat with thisFile in theAttachments
    set the end of theseFiles to alias thisFile
    end repeat”
    eListAttachments=“set theseFiles to {}”

executeapplescript “try”+¶+eListAttachments+“
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:”+applescriptstring(eSubject)+“, content:”+applescriptstring(eBody)+“}
tell newMessage
tell content
    repeat with thisAttachment in theseFiles
    make new attachment with properties {file name:thisAttachment}
    end repeat
    end tell
end tell
”+?(eAttachments <> "","delay 1"+¶,"")+
“send newMessage
end tell
	set scriptResult to "Sent"
on error errMsg number errNum
	set scriptResult to "Error: " & errMsg & "(" & errNum & ")"
end try
return scriptResult”

if eResult match {"*"}
    eResult=replace(replace(eResult[2,-2],{\"},{"}),{\\},{\})   /* AppleScript puts quotes around returned text values and escapes " and \ */

//displaydata eResult

if eResult=""
    eResult="AppleScript did not compile."

On reflection, I should add that you can either replace the code of the custom statement zemailwithattachments with the revised code, which would be simplest, or add a new custom statement called zemailattachments containing the code (which would mean you have to change the statement name to zemailattachments in all your procedures using zemailwithattachments).

Thanks Dave. This is going to be very helpful.
I had an earlier version of this statement that called for inserting the complete path as the third parameter, and presumably the file did not need to be on the desktop.
This version works with the attachment on the desktop, so I am very happy.

I believe the line I quoted above was the change. Some time back, a change in Mail caused the email to be sent before the attachment could be attached. The solution was to insert a one second delay before sending whenever the email included an attachment.

Ah, just so. Thanks again, Dave.