0
$\begingroup$

I am looking to have a program that can shift between a few different email accounts and am personally storing credentials. I noticed that:

    SendMail[<|"To" -> "***@***.***",
 "Subject" -> "SubjectForEmail",
  "Body" -> "SomeText", "From" -> "***@***.**", 
 "Server" -> "smtp.***.***", "UserName" -> "***@***.**", 
  "Password" -> "***", "PortNumber" -> 587, 
 "EncryptionProtocol" -> "StartTLS"|>]

Works great. However:

    SendMail[Join[<|"To" -> "***@***.***",
  "Subject" -> "SubjectForEmail",
  "Body" -> "SomeText", "From" -> "***@***.**", 
 "Server" -> "smtp.***.***", "UserName" -> "***@***.**", 
  "Password" -> "***", "PortNumber" -> 587, 
  "EncryptionProtocol" -> "StartTLS"|>]]

Fails every time and asks for me to sign in with a Wolfram account (obviously ignoring the parameters that it was given)

Note:

Join[<||>]//Head

-> Association

<||>//Head

-> Association

It's the same type and has the same contents. SendMail[] just doesn't like it after it is Join[]ed.

Have I missed something in the SendMail[] or Join[] documentation? Is this something special about Associations?

Any help is appreciated.

EDIT:

After goofing around with this, I figured out that SendMail[#]& @ Join[<|...|>] works for some reason. (Note: SendMail @ Join[<|...|>] does not work)

I'm not marking this as answered yet because I have absolutely no idea why this solution works and would appreciate any insight you might have.

$\endgroup$
2
  • 1
    $\begingroup$ What happens if you use Identity instead of Join ? What happens if you do SendMail[Evaluate[Join[...]]] ? $\endgroup$
    – flinty
    Commented Jul 19, 2020 at 20:20
  • $\begingroup$ No luck with Identity but SendMail[Evaluate[Join[...]]] seems to work. I think that solves it. I had no idea that SendMail[] might hold the evaluation. $\endgroup$ Commented Jul 20, 2020 at 2:02

1 Answer 1

1
$\begingroup$

It seems that SendMail[...] holds the evaluation until later. To counteract this, use the pure function that I suggested in my post or use the solution proposed by flinty which is SendMail[Evaluate[Join[...]]]

$\endgroup$
1
  • 1
    $\begingroup$ I suspected this much. It's a shame the documentation of SendMail doesn't seem to mention it anywhere. $\endgroup$
    – flinty
    Commented Jul 20, 2020 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.