जावा का उपयोग करके ईमेल कैसे भेजें

इस सरल ट्यूटोरियल में, हम यह पता लगाएंगे कि जावा का उपयोग करके ** कैसे भेजें Email**। SMTP लोकप्रिय ईमेल क्लाइंट में से एक है और आप सीखेंगे कि Java में Gmail SMTP का उपयोग करके ईमेल कैसे भेजें। एप्लिकेशन सरल एपीआई कॉल का उपयोग करता है जिसका उपयोग विंडोज और लिनक्स ऑपरेटिंग सिस्टम के अंदर जावा वातावरण में किया जा सकता है।

जावा का उपयोग करके ईमेल भेजने के चरण

  1. मावेन रिपोजिटरी से Aspose.Email JAR फ़ाइल संदर्भ जोड़कर एप्लिकेशन को कॉन्फ़िगर करें
  2. ईमेल भेजने के लिए MailMessage class इंस्टेंस बनाएं
  3. वांछित मेल संदेश के विभिन्न गुण सेट करें
  4. SmtpClient गुण सेट करें और ईमेल संदेश भेजें

SMTP ईमेल भेजने और प्राप्त करने के लिए सबसे सरल ईमेल क्लाइंट में से एक है। निम्नलिखित उदाहरण में, हमने भेजे जाने वाले संदेश को बनाने के लिए MailMessage Class का उपयोग किया है। इसमें ईमेल विषय, प्राप्तकर्ता और ईमेल बॉडी सेट करना शामिल है। फिर हम SmtpClient ऑब्जेक्ट को इनिशियलाइज़ करेंगे जिससे हम पोर्ट और होस्ट जानकारी के साथ उपयोगकर्ता के लिए क्रेडेंशियल सेट करेंगे। अंत में, हम उस मेल संदेश को भेजेंगे जिसे हमने पहले चरण में बनाया था। निम्नलिखित उदाहरण आसान कार्यान्वयन है कि कैसे जावा में एसएमटीपी सर्वर का उपयोग करके मेल भेजें

जावा का उपयोग करके ईमेल भेजने के लिए कोड

package testemail;
import com.aspose.email.License;
import com.aspose.email.MailAddressCollection;
import com.aspose.email.MailMessage;
import com.aspose.email.SecurityOptions;
import com.aspose.email.SmtpClient;
public class EmailKB {
public static void main(String[] emailArguments) {
// Apply the Aspose.Email license before sending email through Gmail SMTP
License emailLicense = new License();
emailLicense.setLicense("EmailLicense.lic");
// Create MailMessage instance to send email
MailMessage testEmailMessage = new MailMessage();
// Set properties of desired mail message
testEmailMessage.setSubject("How to Send Mail Using SMTP Server in Java");
// Adding the destination email address or addresses
MailAddressCollection mailAddresses = new MailAddressCollection();
mailAddresses.add("TestReceiverEmail@EmailServer.com");
testEmailMessage.setTo(mailAddresses);
testEmailMessage.setBody ("This is a test for sending email using SMTP using Java.");
// Create SmtpClient class object to send email
SmtpClient emailClient = new SmtpClient();
// Setting the SmtpClient properties to set the credentials, host and port
emailClient.setHost("smtp.gmail.com");
emailClient.setUsername("YourSourceEmail@gmail.com");
emailClient.setPassword("Your Password for Gamil");
emailClient.setPort(587);
emailClient.setSecurityOptions(SecurityOptions.SSLExplicit);
// Initiate the email message using Gmail's SMTP client
emailClient.send(testEmailMessage);
}
}

पिछले विषय में, हमने उदाहरण प्रस्तुत करने पर ध्यान केंद्रित किया और जावा का उपयोग करके पीएनजी को लाटेक्स कैसे प्रस्तुत करें? की खोज की। यह विषय सरल दृष्टिकोण का उपयोग करके ईमेल भेजने के लिए जावा एसएमटीपी का उपयोग करने पर केंद्रित है।

 हिन्दी