Android
 Computer >> コンピューター >  >> プログラミング >> Android

Kotlinを使用してAndroidアプリを使用してHTMLメールを送信するにはどうすればよいですか?


この例は、Kotlinを使用してAndroidアプリを使用してHTMLメールを送信する方法を示しています。

ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。

ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
   xmlns:tools="https://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="70dp"
      android:background="#008080"
      android:padding="5dp"
      android:text="TutorialsPoint"
      android:textColor="#fff"
      android:textSize="24sp"
      android:textStyle="bold" />
   <Button
      android:layout_centerInParent="true"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:onClick="sendHtmlEmail"
      android:text="Send HTML Email" />
</RelativeLayout>

ステップ3 −次のコードをsrc / MainActivity.kt

に追加します
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.Html
import android.view.View
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
      title = "KotlinApp"
   }
   fun sendHtmlEmail(view: View?) {
      val mailId = "yourmail@gmail.com"
      val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", mailId, null))
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject text here")
      emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p><b>Some Content</b></p>" +
      "https://www.google.com" + "<small><p>More content</p></small>"))
      startActivity(Intent.createChooser(emailIntent, "Send email..."))
   }
}

ステップ4 −次のコードをandroidManifest.xmlに追加します

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
   package="com.example.q11">
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>

アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、[実行]をクリックします ツールバーのKotlinを使用してAndroidアプリを使用してHTMLメールを送信するにはどうすればよいですか? アイコン。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します。

Kotlinを使用してAndroidアプリを使用してHTMLメールを送信するにはどうすればよいですか?

Kotlinを使用してAndroidアプリを使用してHTMLメールを送信するにはどうすればよいですか?


  1. JavaMail APIを使用してAndroidでメールを送信するにはどうすればよいですか?

    この例は、JavaMailAPIを使用してAndroidでメールを送信する方法を示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="ht

  2. HTMLフォームを使用してメールを送信するにはどうすればよいですか?

    HTMLフォームを使用してメールを送信するには、フォームのaction属性にメールIDを追加する必要があります。その中に、 mailtoを続行するメールを追加します :つまり、 mailto:emailid@example.com 。 例 次のコードを実行して、HTMLフォームを使用してメールを送信してみてください- <!DOCTYPE html> <html>    <body>       <h2>Student Contact Form</h2>   &nb