Authentication for sending an email
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, January 1, 2003 07:36 PM

import java.util.*; import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; class Authenticator { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("userid", "password"); } } public class sms { public static void main(String[] args) throws Exception { String messageBody = "testing 123"; int x; String strEmailAddress = "userid@yahoo.com"; String strSmtpServer = "smtp.mail.yahoo.com"; String to = strEmailAddress; String from   More>>

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

class Authenticator
{

public PasswordAuthentication
getPasswordAuthentication()
{
return new PasswordAuthentication("userid", "password");
}
}


public class sms
{
public static void main(String[] args)
throws Exception {


String messageBody = "testing 123";

int x;

String strEmailAddress = "userid@yahoo.com"; String strSmtpServer = "smtp.mail.yahoo.com";

String to = strEmailAddress;
String from ="userid@yahoo.com";
String host = strSmtpServer;

Properties props = new Properties();
props.put("mail.smtp.host", host);

Authenticator auth = new Authenticator();

Session session = Session.getDefaultInstance(props,auth);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("i miss u");
msg.setSentDate(new java.util.Date());
msg.setText(messageBody );
Transport.send(msg);
}
}

my problem

i get an error
cannot resolve symbol
symbol : method getDefaultInstance (java.util.Properties,Authenticator)
location: class javax.mail.Session
Session session = Session.getDefaultInstance(props,auth);


how to i authenticate my user id when i wan to send my mail?? i really need help here...thanks

   <<Less

Re: Authentication for sending an email

Posted By:   Tolga_KARAKAYA  
Posted On:   Thursday, January 2, 2003 07:12 AM

class Auth extends Authenticator {
String mailusername = "username";
String mailpassword = "pass";
public Auth()
{
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, pass);
}
}

props.put("mail.smtp.auth", "true"); //AUTH AT HERE!!!
Authenticator auth = new Auth();
Session mailsession = Session.getInstance(props, auth);

About | Sitemap | Contact