|
7-Laboratoriya ishi Mavzu: Serverlarda servletlarni yaratish Bajardi
|
Sana | 09.01.2024 | Hajmi | 250,96 Kb. | | #133052 |
Bog'liq 7-Laboratoriya ishi
O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
7-Laboratoriya ishi
Mavzu: Serverlarda servletlarni yaratish
Bajardi: 041-19-guruh talabasi
Zokirov Shoxruhjon
Tekshirdi: Elov J
Toshkent 2024
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.
Kod qismi:
/*
* 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 ElbekSendEmail;
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 ElbekSendEmail {
public static void main(String[] args) {
// Recipient's email ID needs to be mentioned.
String to = "ulugbek0911uz@mail.ru";//change accordingly
// Sender's email ID needs to be mentioned
String from = "elbeknoname1@mail.ru";//change accordingly
final String username = "elbeknoname1@mail.ru";//change accordingly
final String password = "SkMrsfqsSwXWSaCnhvqN";//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()
{
@Override
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("7-Laboratoriya ishi");
// Now set the actual message
message.setText("Assalom alaykum Elbek sizga xabar jo'natdi !!!");
// Send message
Transport.send(message);
System.out.println("Xabar muvaffaqiyatli jo'natildi....");
} catch (MessagingException e) {
//throw new RuntimeException(e);
}
}
}
|
| |