We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Missing LinkedResources Error - Only The Last One Is Sent

Hi Team,


I’ve picked up an issue with the Email API. I’m wondering whether I’m missing something or whether this is a bug. I’m using the latest version of the API, V16.12.0 which we recently purchased.

Here is the scenario:
When I send an HTML email, it only ever attaches the latest image that I add to my LinkedResources list. See my code below. For example, when I add the Header
and the Footer, I only see the Footer in the received email. When I add the Header,
the Footer and the Trailer, I only see the Trailer in the received email.

But, in all cases, when I save the email to disk, all the images are in the email. So please don’t
save it because that is not the scenario. This only happens when you directly Send the MailMessage using SmtpClient without saving the message first.

Please let me know if you’re able to reproduce this behaviour or if I’m missing some
configuration setting. I’ve also attached our HTML for your to see.

Thanks.



public void sendHtmlEmailWithAspose(String recip, String subject, String htmlContent) {
try {
License license = new License();
license.setLicense("/opt/aspose_total_java_v16.lic");

MailMessage msg = new MailMessage();

msg.setFrom(new MailAddress(“noreply@company.co.za”, “Display Name”));
msg.getTo().add(recip);
msg.setSubject(subject);
msg.setHtmlBody(htmlContent);

LinkedResource headerResource = new LinkedResource("/opt/email_header.png", MediaTypeNames.Image.PNG);
headerResource.setContentId(“header_image_cid”);
msg.getLinkedResources().addItem(headerResource);

LinkedResource footerResource = new LinkedResource("/opt/email_footer.png", MediaTypeNames.Image.PNG);
footerResource.setContentId(“footer_image_cid”);
msg.getLinkedResources().addItem(footerResource);

LinkedResource trailerResource = new LinkedResource("/opt/email_header.png", MediaTypeNames.Image.PNG);
trailerResource.setContentId(“trailer_image_cid”);
msg.getLinkedResources().addItem(trailerResource);

SmtpClient client = new SmtpClient();

client.setHost(serverName);
client.setPort(portNumber);
client.setSecurityOptions(SecurityOptions.None);

client.send(msg);
} catch (Exception e) {
System.out.println("Unable to send Aspose Email: " + e.getMessage());
}
}

Hi Eugene,

Thank you for writing to Aspose Support team.

We have tested this issue at our end with the latest version of Aspose.Email for Java 17.2.0 and were not able to observe any such problem at our end. We made some rectifications to your code that is as under and sent the email using the Exchange Server account as SMTP. Please try it with the latest version of the API and let us know your feedback.

Sample Code:

static public void Email_827866_SendHtmlEmailWithAspose(String recip, String subject, String htmlContent)

{

try

{

//License license = new License();

[//license.setLicense](https://license.setlicense/)("/opt/aspose_total_java_v16.lic");

MailMessage msg = new MailMessage();

msg.From = new MailAddress("asposeemail.test4@aspose.com", “Aspose Test4”);

msg.To.Add(recip);

msg.Subject =subject;

msg.HtmlBody = htmlContent;

LinkedResource headerResource = new LinkedResource(@“D:\Aspose_DotNetProjects\Email\AE\Email_827866\header.png”, MediaTypeNames.Image.Png);

headerResource.ContentId = “header_image_cid”;

msg.LinkedResources.Add(headerResource);

LinkedResource footerResource = new LinkedResource(@“D:\Aspose_DotNetProjects\Email\AE\Email_827866\footer.png”, MediaTypeNames.Image.Png);

footerResource.ContentId = “footer_image_cid”;

msg.LinkedResources.Add(footerResource);

LinkedResource trailerResource = new LinkedResource(@“D:\Aspose_DotNetProjects\Email\AE\Email_827866\trailer.png”, MediaTypeNames.Image.Png);

trailerResource.ContentId = “trailer_image_cid”;

msg.LinkedResources.Add(trailerResource);

using (SmtpClient smtpClient = new SmtpClient(“[exchange.aspose.com](http://exchange.aspose.com/)”, "asposeemail.test4@aspose.com", “Aspose2017”))

{

smtpClient.Send(msg);

}

[//msg.Save](https://msg.save/)(@“D:\Aspose_DotNetProjects\Email\AE\Email_827866\output.msg”,MsgSaveOptions.DefaultMsgUnicode);

}

catch (Exception e)

{

Console.WriteLine(e.Message);

[//System.out.println](https://system.out.println/)("Unable to send Aspose Email: " + e.getMessage());

}

}

Hi Kashif,


Thanks for your response.

However, you are showing me the .NET code whereas I’m using the Java version.
I’ve updated to V17 anyway, same issue still happens.

Please test for Java version and advise.

Regards,
Eugene.

Hi Eugene,

I have tested the issue using Aspose.Email for Java 17.2.0 and observed that all the linked resources are rendered fine on the receiving end. All the three images header, footer and trailer are rendered on right place. You may please give a try to the following sample code and share the feedback.

static public void Email_827866()
{
String html = readFile(“HtmlBodyContent.txt”,StandardCharsets.UTF_8);
Email_827866_SendHtmlEmailWithAspose("user2@domain.com", “My subject by Java”, html);
}

static public void Email_827866_SendHtmlEmailWithAspose(String recip, String subject, String htmlContent)
{
try
{
MailMessage msg = new MailMessage();

msg.setFrom(new MailAddress("user1@domain.com", “password”));
msg.getTo().add(recip);
msg.setSubject(subject);
msg.setHtmlBody(htmlContent);

LinkedResource headerResource = new LinkedResource(“header.png”, MediaTypeNames.Image.PNG);
headerResource.setContentId(“header_image_cid”);
msg.getLinkedResources().addItem(headerResource);

LinkedResource footerResource = new LinkedResource(“footer.png”, MediaTypeNames.Image.PNG);
footerResource.setContentId(“footer_image_cid”);
msg.getLinkedResources().addItem(footerResource);

LinkedResource trailerResource = new LinkedResource(“trailer.png”, MediaTypeNames.Image.PNG);
trailerResource.setContentId(“trailer_image_cid”);
msg.getLinkedResources().addItem(trailerResource);

SmtpClient smtpClient = new SmtpClient(“[exchange.domain.com](http://exchange.domain.com/)”, "user@domain.com", “password”);
{
smtpClient.send(msg);
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = new byte[0];
try {
encoded = Files.readAllBytes(Paths.get(path));
} catch (java.io.IOException e) {
e.printStackTrace();
}
return new String(encoded, encoding);
}

Hi Kashif,


Thanks for your time and effort.

The code above did not work for me. However, we will be testing it from another Linux VM to see if we’re running into the same issue.

Just as a side-note, it works with all SMTP servers when I run the code from a Windows machine. We only see this happening from our Linux machine. But, as I mentioned, we’ll spin up a clean VM and test from there.

Thanks again.

Regards,
Eugene.

Hi Eugene,


Thank you for sharing your feedback. Please let us know with your feedback as soon as there is some clear feedback available in this regard.