Skip to content

Instantly share code, notes, and snippets.

@mrtampan
Last active January 20, 2020 19:50
Show Gist options
  • Save mrtampan/5cc6799fcda55ccc528d5d78c3e97818 to your computer and use it in GitHub Desktop.
Save mrtampan/5cc6799fcda55ccc528d5d78c3e97818 to your computer and use it in GitHub Desktop.
javamail simple sender
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value="test")
public class TestController{
@Autowired
public JavaMailSender emailSender;
public void sendSimpleMessage(
String to, String subject, String text, String from) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
message.setFrom(from);
try {
emailSender.send(message);
}catch (Exception e) {
e.printStackTrace();
}
}
@GetMapping(value="send")
@ResponseBody
public String kirimEmail() {
sendSimpleMessage("[email protected]", "Testing Your sping", "asdadasda", "[email protected]");
return "sukses";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment