Jump to content

Sending mail with attachments through smtp


This topic is 3871 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Good afternoon,
I implemented the  module present in the demo file of Scriptmaster entitled "Send Email With Attachments".
I do not meet problem - excepted a relative slowness via my ISP -smtp.free.fr and the mails are forwarded with their attachment.
Yesterday finding me at a friend's home, I changed the smtp in question for that of his ISP (smtp.orange.fr ): and then nothing is transmitted (message and attachment) !

Some forums tell to fix the port to 587 but how in the smtphost field ?

 

Thanks

Noël

Link to comment
Share on other sites

John

I tried as you said (I think) by adding as follows, once with simple quotes, once with double quotes...

 

import javax.mail.*;
import javax.mail.internet.*;

Properties props = new Properties();
props.setProperty("mail.smtp.host", smtpHost);
props.setProperty("mail.smtp.port", 587);

MimeMessage msg = new MimeMessage(Session.getInstance(props));
Multipart content = new MimeMultipart();

I have always an error and the text returned is

 

groovy.lang.MissingMethodException: No signature of method: java.util.Properties.setProperty() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [mail.smtp.port, 587]
Possible solutions: setProperty(java.lang.String, java.lang.String), getProperty(java.lang.String), getProperty(java.lang.String, java.lang.String), hasProperty(java.lang.String), getProperties()

Parameters:
{[email protected], [email protected], subject=Envoi avec Cerfa, body=I'm testing the "sending email with attachments" utility in ScriptMaster.  Works great! Special characters test: éüîñ, smtpHost=smtp.orange.fr, attachmentPath=/Users/ND/Desktop/codes site PEP83.pdf}

---Script---
Script:
import javax.mail.*;
import javax.mail.internet.*;

Properties props = new Properties();
props.setProperty("mail.smtp.host", smtpHost);
props.setProperty("mail.smtp.port", 587);

MimeMessage msg = new MimeMessage(Session.getInstance(props));
Multipart content = new MimeMultipart();
// first the message body
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setText(body, "UTF-8");
content.addBodyPart(bodyPart);
// then the attachment
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(attachmentPath);
content.addBodyPart(attachmentPart);
msg.setContent(content);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
Transport.send(msg);
return true

And this is not very speaking for me (two years ago java was only an exotic dance for me )

Thanks for help

Noël

Link to comment
Share on other sites

Hello !

Finallly I just found my error in the adptation of the script contained in the demo file. I used finally the script with authentification and added the line props.setProperty('mail.smtp.port', 587) replacing 587 by a fm_port_smtp value. If someone needs file contact me.

Thanks and have a good week-end

Noël

Link to comment
Share on other sites

This topic is 3871 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.