Incorrect sender when sending email through Applescript

The example below is presented in a form that I have been using for several years. And basically, this is a well-known method of sending emails using Applescript.

tell application "Mail" set newMessage to make new outgoing message with properties {subject:"IP Address", content:"Your IP Address Is: 86.195.132.134"} tell newMessage set visible to false set sender to " mark@sender.com " make new to recipient at end of to recipients with properties {address:" recipient@mac.com "} send end tell end tell 

What I just noticed today is the 'sender' email installed in the script, maybe not one Mail.app if its mailbox is not selected. Random will be used if the main mailbox is selected or an individual mailbox is selected, then the address from his account will be used.

I think this is due to the fact that in the Mail settings in the Composing section. There is the option "Send new messages from:"


enter image description here


You cannot select "NO". The only options are "Select selected mailbox" or one of the email addresses that are in the drop-down list.

I must admit, I do not know if this was before I went to Leo.

Does anyone know about this, or if it is a known bug?

Thanks.

+3
source share
3 answers

this worked for me just now, hope this helps:

 tell application "Mail" set theOutMessage to make new outgoing message with properties {visible:true} tell theOutMessage make new to recipient at end of to recipients with properties {address:" first@mail.com "} set sender to "Name Surname < name.surname@mail.com >" set subject to "Message Subject" set content to "Message Text" end tell end tell 
+8
source

I don’t know where I got it from, but the sender needs a specific format. It should be:

 full name <email_address> 

You look at the settings of your Mail account and use the fields "Full name" and "Email address" on one of the accounts ... but put them in the form that I showed. I just checked and this format works for me. Therefore, I use this in my applications ...

 set emailSender to "FirstName LastName < hank@sender.com >" 
+1
source

If you are looking for a script that will send an email, this should work.

 set theRecipient to text returned of (display dialog "Who would you like to email" default answer "" buttons {"Cancel", "Ok"} default button 2) set theSubject to text returned of (display dialog "What is the subject" default answer "" buttons {"Cancel", "Ok"} default button 2) set theContent to text returned of (display dialog "What would you like to say" default answer "" buttons {"Cancel", "Ok"} default button 2) tell application "Mail" set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true} tell theNewMessage make new to recipient at end of to recipients with properties {address:theRecipient} send tell application "Mail" activate end tell end tell end tell 
0
source

Source: https://habr.com/ru/post/892420/


All Articles