I have an android app for send sms to email. Improve my app by adding background working this app. I need to open this app and then it should run in the background
My MainActivity.kt file:

package com.example.smstoemailforwarder

import android.Manifest
import android.content.pm.PackageManager
import android.os.AsyncTask
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import java.util.Properties
import javax.mail.Message
import javax.mail.MessagingException
import javax.mail.PasswordAuthentication
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage

class MainActivity : AppCompatActivity() {
    private val MY_PERMISSIONS_REQUEST_RECEIVE_SMS = 1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val smsTextView: TextView = findViewById(R.id.tv_sms_message)
        val sendEmailButton: Button = findViewById(R.id.btn_send_email)

        // Check if the RECEIVE_SMS permission is granted
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
            // Request the RECEIVE_SMS permission
            ActivityCompat.requestPermissions(this,
                arrayOf(Manifest.permission.RECEIVE_SMS, Manifest.permission.READ_SMS, Manifest.permission.INTERNET), MY_PERMISSIONS_REQUEST_RECEIVE_SMS)
        }

        SmsReceiver.smsLiveData.observe(this, Observer { message ->
            smsTextView.text = message
            SendEmailTask().execute()
        })

        sendEmailButton.setOnClickListener {
            val message = smsTextView.text.toString()
            if (message.isNotEmpty()) {
                SendEmailTask().execute()
            } else {
                Toast.makeText(this, "No SMS message to send", Toast.LENGTH_SHORT).show()
            }
        }
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        if (requestCode == MY_PERMISSIONS_REQUEST_RECEIVE_SMS) {
            if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission granted
            } else {
                // Permission denied
            }
        }
    }

    private inner class SendEmailTask : AsyncTask<String, Void, Boolean>() {
        override fun doInBackground(vararg params: String): Boolean {
            val username = params[0]
            val password = params[1]
            val recipient = params[2]
            val subject = params[3]
            val messageBody = params[4]
            return try {
                val props = Properties()
                props["mail.smtp.auth"] = "true"
                props["mail.smtp.starttls.enable"] = "true"
                props["mail.smtp.host"] = "smtp.gmail.com"
                props["mail.smtp.port"] = "587"

                val session = Session.getInstance(props,
                    object : javax.mail.Authenticator() {
                        override fun getPasswordAuthentication(): PasswordAuthentication {
                            return PasswordAuthentication(username, password)
                        }
                    })

                val message = MimeMessage(session)
                message.setFrom(InternetAddress(username))
                message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient))
                message.subject = subject
                message.setText(messageBody)

                Transport.send(message)
                Log.d("MainActivity", "Email sent successfully!")
                true
            } catch (e: MessagingException) {
                e.printStackTrace()
                Log.e("MainActivity", "Error sending email", e)
                false
            }
        }

        override fun onPostExecute(result: Boolean) {
            val context = this@MainActivity
            if (result) {
                Toast.makeText(context, "Email sent successfully!", Toast.LENGTH_SHORT).show()
            } else {
                Toast.makeText(context, "Failed to send email", Toast.LENGTH_SHORT).show()
            }
        }
    }
}