I am trying to remove/delete a message from a folder in Java mail (after I have copied it to another) here is my code:
Flags deleted = new Flags("DELETED");
folder.setFlags(messages, deleted, true);
folder.expunge();
The message is not affected. Can someone please show me the proper way to do this?
Flags deleted = new Flags(Flags.Flag.DELETED);
folder.setFlags(messages, deleted, true);
folder.expunge(); // or folder.close(true);
Related
I'm trying to make a snipe command that fetches more than one deleted message that was sent earlier in a specific channel. For now, all I can do is snipe the last deleted message. This is my code :
const msg = client.snipes.get(message.channel.id);
if (!msg) return message.channel.send('There is no message to snipe. :eyes:')
const snipeEmbed = new Discord.MessageEmbed()
.setAuthor(msg.author.tag, msg.author.displayAvatarURL())
.setDescription(msg.content)
message.channel.send(snipeEmbed);
Now, that part of the code works perfectly fine, can someone show me how to do it with more than one deleted message ? I'm trying to make it so I could type "-snipe 2" to get the second oldest message that has been deleted. I don't know if I was clear or not, but help would be appreciated !
I have created a HTML email form which allows a user to enter To, subject, message, content and attachments however I cannot get the attachments to send.
I have researched online and came across many variations of this code:
messageBodyPart = new MimeBodyPart();
String filename = "/home/manisha/file.txt";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
But is there a way of sending attachments input into the form instead of adding the file path to a file in the code?
Thanks
First, the files need to be uploaded from the browser to the server using the html form. Depending on what you're using to manage the uploaded data, you can store the file data in memory or in files on the server. If you store it in memory, you can use a ByteArrayDataSource instead of FileDataSource in your code above.
I am trying to get a file with the .rtf extension as an attachment with an email. I cannot seem to get it in my mailbox.
the code I currently use
try
{
Message msg = new MimeMessage(session);
msg.setFrom( ); // this is filled in but hidden for this question
msg.addRecipient();// this is filled in but hidden for this question
msg.setSubject("test email");
msg.setText("body test content");
msg.setSentDate(new Date());
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
FileDataSource source = new FileDataSource(receiveFile);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.attachFile(backupFile);
messageBodyPart.setFileName("reportFile.rtf");
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
Transport.send(msg);
}
receiveFile is the rtf file in question that needs to be send as an attachement.
Do not bother wtih server settings and such. I have send emails using this code so that works all just fine :). and had success sending .txt or .doc files as well so I know my info is correct. just when I try to send it as reportFile.rtf the mail just does not arrive. and I have tried 2 systems both together (the datahandler + source path and the attachFile path) and both did not really give me what I wanted.
Is a rtf file as attachment possible using javaMail or am I looking in the wrong direction?
After looking at it more closely with my co-worker we figured out that the email I used as sender was interperted as a spam and thus dumped it in the spam folder. now in itself this is not a problem since it was fine for testing. However it seems that if you keep spamming with that address the mail server indeed blocks like a good percentage of the mails i was sending. So this made it hard to debug since it sometimes got through and sometimes did not. the issues has been resolved now.
This is my code for attaching the files to the mail:
Multipart mp=new MimeMultipart("mixed");
BodyPart mbody=new MimeBodyPart();
mbody.setHeader("Content-Type", "text/html; charset=us-ascii");
mbody.setHeader("Content-Transfer-Encoding","7bit");
mbody.setContent(content2, "text/html");
mp.addBodyPart(mbody);
for(File file:f){
BodyPart mbody2=new MimeBodyPart();
DataSource ds=new FileDataSource(file.getAbsolutePath());
mbody2.setDataHandler(new DataHandler(ds));
mbody2.setFileName(ds.getName());
mbody2.setHeader("Content-Type", "multipart/mixed");
mbody2.setHeader("Content-Transfer-Encoding", "base64");
mp.addBodyPart(mbody2);
}
m.setContent(mp);
content2 is the html content I am embedding in the E-mail, and I am adding files from an arraylist f.
The problem here is that although the files get attached and I receive the E-mail fine, I am unable to open the attachments because the data is corrupt. This happens for all the files I've tried to attach like jpegs, pdfs, spreadsheets, word docs and txt files.
I read here: https://community.oracle.com/thread/1589120 that this could happen because JavaMail uses encoding that messes up the binary data of the file and adding mbody2.setHeader("Content-Transfer-Encoding", "base64"); should fix the problem but that doesn't work for me.
Any ideas on what could be wrong?
Thanks
Time for some debugging...
First, remove all of the setHeader calls; some of them are wrong and none of them should be necessary.
Next, determine if the problem is on the sending end or the receiving end. Try multiple mail readers to see if they all have problems with the attachments.
Try sending plain text attachments. Are they also corrupted?
Post the protocol trace showing what happens when you send a simple message with a simple attachment that fails, so we can see if the message is being constructed correctly.
What version of JavaMail are you using?
What mail reader are you using to view the attachments?
My silverlight application is supposed to send an e-mail at some point to the preset e-mail address.
So far so good, it actually sends the e-mail.
My problem starts when I want to embed an image. This is one of many sample codes I'm actually using:
string Body = "<b>This is a test E-Mail</b><br><BR>This E-mail is being sent as part of beta testing...<BR><img alt=\"\" src=\"cid:imageId\" >";
ContentType ct = new ContentType(MediaTypeNames.Image.Jpeg);
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
LinkedResource imagelink = new LinkedResource(#"C:\\Users\\David\\Desktop\\Projectos\\WorkIt\\Resources\\Imagens\\workitlogosmall.jpg", ct);
imagelink.ContentId = "imageId";
imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(imagelink);
mail.AlternateViews.Add(htmlView);
mail.IsBodyHtml = true;
I'm receiving the e-mail with the text formatted, but instead of the image, I get a gray box.
What's going on? I've tried different approaches to get the path for the image, but always with the same result!!
Can anyone explain what I'm doing wrong???
Forget about it... I've solved the issue.
It has nothing to do with with the code, the code WORKS fine.
The e-mail account that I'm using to receive the email's is one of my oldest and I don't use it that often, so I've completely forgotten that I had the "Show Content" deactivated for every mail that I receive (duh) and that's why it blocked the image I was sending.
I actually felt pretty stupid after realizing that.
Anyway, hope this helps anyone who is as distracted as I am :)