silverlight mailmessage embedde image is gray - silverlight

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 :)

Related

Discord.js - Detect if a message has an image or a link

So I'm something of a beginner to making bots and I'm semi-comfortable in the space I'm at now only poking around at Discord.js, but I've encountered an issue that I can't seem to move forward on.
I have something of a joke bot that's supposed to detect if a person's sent an image or a link, output a reply, and then delete the image (or link). (Really, I'd prefer to delete anything that isn't text, but I need the response to say exactly what kind of media it is, so I don't care if it's particularly limited...)
Here's what I have:
//remove instances of images
if (message.attachments.length > 0) {
message.channel.send(`${message.author} sent an image!`);
message.channel.send('This constitutes revelry and merriment and is strictly outlawed!')
message.delete();
}
//remove instances of links
if (message.embeds.length > 0) {
message.channel.send(`${message.author} sent an link!`);
message.channel.send('This constitutes revelry and merriment and is strictly outlawed!')
message.delete();
}
However, if I send an image, it simply does nothing.
Thanks in advance!
edit: I'd also like to say that the bot has other functionality that works perfectly (reacting, deleting, replying to mentions of certain words), so hopefully the only relevant code should be above.
message#attachments is a Collection so you have to use:
message.attachments.size

sending a .rtf file with javaMail

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.

java mail attachments getting corrupted

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?

How to remove default disclaimer in javamail

When sending emails via javamail, the following is always appended to the bottom of each message:
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager. This message contains confidential information and
is intended only for the individual named. If you are not the named
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system. If you
are not the intended recipient you are notified that disclosing,
copying, distributing or taking any action in reliance on the contents
of this information is strictly prohibited.
How does one prevent this?
(NOTE: This problem is extremely frustrating to research on the web due to the fact that a disclaimer of this form is attached to so many indexed documents! :-(
JavaMail is not doing that, it is your outgoing SMTP server appending it to each message, probably set up by IT.
To confirm, you can use gmail's servers (with a personal account) and you will see it does not get added to the messages.
This should work. Pay attention to the form in which email body get parsed. In my case the emailBody string is on one line, so you have to put the "#Your disclaimer Here#" on one line. Answer for who will come in future.
public String deleteDisclaimer(String emailBody) {
String disclaimer = "#Your disclaimer here#";
if (emailBody.contains(disclaimer)) {
System.out.println("Deleting Disclaimer..");
return emailBody.substring(0,emailBody.indexOf(disclaimer));
}
System.out.println("DISCLAIMER NOT FOUND!");
return emailBody;
}

wpf "emailto" - with attachments

I am developing a WPF app in MVVM presentation pattern. I have a grid and I am trying to have an "emailto" hyperlink and when the user clicks that i am trying to export all the data to an excel and open the default email client with a draft new message window(email client could be Lotus/Outlook) and attach the excel as an attachment to the mail. I am able to define a "Mailto" hyperlink and when i click that i am able to open the draft message email window. But i am not sure how to send the excel as an attachment. Any help is greatly appreciated.
By sending an Excel file you don't mean generating of this file somehow. Right? So you just need to attach a file.
I always use Andrew Baker's MAPI wrapper class which seems to be very reliable and has never failed for last 6 years. It's just 18Kb of C# code and it does exactly what you need.
var message = new MapiMailMessage(subject, body);
message.Recipients.Add(mailAddress);
message.Files.Add(filePath);
message.ShowDialog();
You could use Simple MAPI API to solve your problem:
var mapi = new Mapi();
mapi.Logon(IntPtr.Zero);
foreach (var filePath in files)
mapi.Attach(filePath);
mapi.Send("subject", "body text", true /* show send message dialog to user */);
mapi.Logoff();

Resources