This may not help you as I'm not really answering your question, but could it be simpler for you if you used Send via E-mail Client rather than SMTP?
Yeah, I think you are on the right track. The email script can draw the smpt settings from the related user table.
Presumably, you want the student to reply directly to the teacher's account wherever that maybe hosted.
You can always configure the SMTP email to show that it is from the teacher (Reply To Field) and use an admin account and email for authenitcation since you probably do not know the teacher's password.
It really depends on if you want the email to pop up in front of the teacher to possibly edit the message or not. If you don't want that to happen, you'll need to use SMTP instead of Client Email settings.
Personally, I set up all servers with FileMaker as a service to also have SMTP email on it with auto relay for email from 127.0.0.1 (from itself or local host). That way my FileMaker SMTP emails never need authenticated and that completely skips the issue of not knowing a password.
I agree with this direction. There may be many ways to create an SMTP solution with lots of development and some work arounds, but by far, the simplest and least time consuming solution is to use the 'Send Mail' via Email client.