Hi i am trying to send an email from outlook 2010 with the help of below code.
package javamail;
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 JavaMailTest {
public static void main(String[] args) {
String host="host";
final String user="[email protected]";//change accordingly
String to="[email protected]";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "false");
Session session=Session.getDefaultInstance(props, null);
session.setDebug(true);
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.saveChanges();
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Test mail");
message.setText("This is test mail.");
//send the message
Transport.send(message);
System.out.println("message sent successfully...");
}
catch (MessagingException e) {e.printStackTrace();}
}
}
The above code works properly and i am able to send the mail(after my tech admin enabled relaying on server). But the problem is i am not able to see the sent mail in my outlook. On analysis i found out that java mail api sends the mail directly from the smtp server. But i want the mail to send from my outlook profile i.e i should be able to see it in my sent mail folder. How should i do it? What api or 3rd party open source library can be used to achieve this?
what is VBA/Office scripting?Go ahead and look it up! You might also be able to use standard .NET to do this as well; I would recommend just doing some additional research. - admdrew