Forums de discussion

Problem with sending mail via MimeMessage

Toshiro Mifune, modifié il y a 8 années.

Problem with sending mail via MimeMessage

Regular Member Publications: 238 Date d'inscription: 11/12/14 Publications récentes
There is a problem with sending message .... I ca send body part of message or some file, but not both .. I dont understand this ...
My code:

Properties props = new Properties();
String subject = "Form message";
String body = "Name : " + fname + "\n\nPhone : " + phone + "\n" + cities;
			        
String host = "*******";
String port = "**";
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
Session sess = Session.getInstance(props);
MimeMessage message = new MimeMessage(sess);
					
message.setFrom(new InternetAddress(email));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("***@***.com"));
message.setSubject(subject, "UTF-8");
message.setSentDate(new Date());
message.setContent(body, "text/html; charset=utf-8");
message.setFileName(file.getFileName());


If I comment comment setFileName, it send me a body text but not attachment (of course) and if I uncomment setFileName ... body text will be not sent, only that file.
Problem is I cant sent it both ... file and body text at a same time, in one message ... any idea?
Toshiro Mifune, modifié il y a 8 années.

RE: Problem with sending mail via MimeMessage

Regular Member Publications: 238 Date d'inscription: 11/12/14 Publications récentes
Maybe is problem with this file ... because if I send it ... for example image, but the after it is downloaded I cant open it ...
my code for this attachment :

private UploadedFile file;
    public UploadedFile getFile() {
        return file;
    }
 
    public void setFile(UploadedFile file) {
        this.file = file;
    }
...
message.setFileName(file.getFileName());
Toshiro Mifune, modifié il y a 8 années.

RE: Problem with sending mail via MimeMessage

Regular Member Publications: 238 Date d'inscription: 11/12/14 Publications récentes
How to get path of uploaded file? How to send file via message? Please give me a simple example, thanks