1

Error in java plugin.

Pease_Xpress 7/30/13 7:07 pm
138
7/30/2013 7:42 pm
So, I want to make a plugin that sends an email to me when my server starts. Don't ask why.

Here is my code:
package me.pease.emailer;

import java.util.Properties;
import java.util.logging.Logger;

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;

import org.bukkit.plugin.java.JavaPlugin;

public class emailer extends JavaPlugin
{

private static final Logger log = Logger.getLogger("Minecraft");
public void onEnable()
{
log.info("[Email] and email has been sent!");
email();

}
public void email(){
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[U]Username[/U]","Password");
//[U]Username[/U] is the [U]username[/U] to your actual email...
//Password is the password you use to log into that email address
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("address[U]@whatever.com[/U]"));
//address[U]@whatever.com[/U] is what you want the email's FROM area to look like, although it seems it just uses the email you logged in with...
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to[U]@email.com[/U]"));
//to[U]@email.com[/U] is the address you are sending this email to
message.setSubject("[[U]Emailer[/U]] Your server has just come online!");
message.setText("The server that we are running has started. People are most likely playing on it because it is SO AWESOME!");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
public void onDisable()
{

}
}


The problem im having: The { on public class emailer extends JavaPlugin
{
is messing my script up. any helpers that will help me??? This is my 2nd java plugin :/

Thanks guys and sorry if it is off-topic!
- Pease
Posted by
Pease_Xpress
Level 24 : Expert Taco
16

  Have something to say?

JoinSign in

1

aman207
07/30/2013 7:42 pm
Level 40 : Master Cake
I am not getting any errors on the { brackets

Try to copy and paste your code into a test project to see if that works.
1

Welcome