The only way to avoid the user from changing email text is to issue the mail
programmatically, i.e. with no UI. It is usually done in Android by using the JavaMail API.
Send Email via JavaMail
First add lines below to your sender class:
static {
Security.addProvider(new JSSEProvider());
}
JSSEP stands for Java Secure Socket Extension, which is the protocol used for
Gmail authentication that we will later on use.
You can grab a working sample of JSSEProvider at:
https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java
Create a sender class :
public class EmailSender extends javax.mail.Authenticator {
void sendMail(username, password, ) {
...
}
}
We now move to sendMail() method implementation:
Start by setting properties for transmission via Gmail:
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.gmail.com"); // <--------- via Gmail
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(props, this);
And follow by sending the mail:
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setDataHandler(handler);
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
ByteArrayDataSource is a standard implementation. You can grab it from
http://commons.apache.org/proper/commons-email/apidocs/src-html/org/apache/commons/mail/ByteArrayDataSource.html
You wil also need to add the method below, returning the PasswordAuthentication, to your class:
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
Good luck.