O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
LABORATORIYA
ISHI
Mavzu: 7-8-laboratoriya ishi
Bajardi:
Mamadiyorov Soatmurot
Toshkent – 2022
7-laboratoriya ishi
Mavzu: Elektron pochta tarmoq dasturini yaratish
Ishning maqsadi:
Talabalarda Java dasturlash tili javax.mail.* va java.util.* paketlari klasslaridan foydalanib elektron pochta bilan ishlovchi dastur yaratish bo‘yicha amaliy ko‘nikmalar hosil qilish.
Dastur kodi:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg411.pkg19;
/**
*
* @author 01
*/
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;
public class SendEmailUsingMaiRulSMTP {
public static void main(String[] args) {
// Recipient's email ID needs to be mentioned.
String to = "vmlld@hi2.in";//change accordingly
// Sender's email ID needs to be mentioned
String from = "burxon21@mail.ru";//change accordingly
final String username = "burxon21@mail.ru";//change accordingly
final String password = "LCmKE9uA7zhDdGzS97XR";//change accordingly
// Assuming you are sending email through relay.jangosmtp.net
String host = "smtp.mail.ru";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "465");
props.put("mail.smtps.ssl.checkserveridentity", true);
props.put("mail.smtps.ssl.trust", "*");
props.put("mail.smtp.ssl.enable", "true");
// Get the Session object.
Session session = Session.getInstance(props,new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username, password);
}
});
try {
// Create a default MimeMessage object.
Message message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
// Set Subject: header field
message.setSubject("laboratoriya ishi");
// Now set the actual message
message.setText("Assalomu alaykum 411-19 guruh talabasi "
+ "Teshaboyev Burxon");
// Send message
Transport.send(message);
System.out.println("Xabar muvaffaqiyatli jo'natildi....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Do'stlaringiz bilan baham: |