inline image is coming as .bin file while sending email Outlook 2016 - outlook

i am trying to send Inline image in html and it is coming as .bin file
i have already read the answer of this Quesstion
Sending an e-mail with an image inline that is attached comes up as ATT00001 on some computers
but still not able to solve it
string DexuslogoImage2 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images\\DexusTenantNotice.png");
string strBody = strBody.Replace("##DexusNoticeLogo##", "cid:Dexuslogo1");
dynamic htmlView = AlternateView.CreateAlternateViewFromString(_Body.ToString(), null, "text/html");
if (!string.IsNullOrEmpty(_EmailLogo)) {
LinkedResource logo = new LinkedResource(_EmailLogo);
logo.ContentId = "Dexuslogo1";
htmlView.LinkedResources.Add(logo);
}
LinkedResource logo1 = new LinkedResource(_EmailLogo1);
logo1.ContentId = "Dexuslogo2";
htmlView.LinkedResources.Add(logo1);
aMessage.AlternateViews.Add(htmlView);

i have found answer .bin file comes when _EmailLogo1 and _EmailLogo are empty so need
to check if it's empty or not !!
dynamic htmlView = AlternateView.CreateAlternateViewFromString(_Body.ToString(), null, "text/html");
if (!string.IsNullOrEmpty(_EmailLogo1)) {
LinkedResource logo = new LinkedResource(_EmailLogo);
logo.ContentId = "Dexuslogo2";
htmlView.LinkedResources.Add(logo);
}
if (!string.IsNullOrEmpty(_EmailLogo))
{
LinkedResource logo1 = new LinkedResource(_EmailLogo1);
logo1.ContentId = "Dexuslogo2";
htmlView.LinkedResources.Add(logo1);
aMessage.AlternateViews.Add(htmlView);
}

Related

Send a mail with an attachment on my hard drive with Apache commons email

I have a problem to send an attachment in my mail with Apache commons email.
To explain it quick and dirty, the mail is sent but there is no attachment at all when i look at it in Outlook.
I use Apache commons email v1.4 and JAVA 8.
I want to add a log file which is on my hard drive at this location C:\myfolder\myfile.log
This is what i have tried so far to add the attachment
Path logRejetPath = Paths.get("C:\\myfolder\\myfile.log");
Boolean pathExists = Files.exists(logRejetPath, new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
if (pathExists) {
File rejLogFile = new File(logRejetPath.toString());
email.attach(new FileDataSource(rejLogFile), "test", "test");
}
email.send();
Or
Path logRejetPath = Paths.get("C:\\myfolder\\myfile.log");
Boolean pathExists = Files.exists(logRejetPath, new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
if (pathExists) {
File rejLogFile = new File(logRejetPath.toString());
email.attach(rejLogFile);
}
email.send();
Or
Path logRejetPath = Paths.get("C:\\myfolder\\myfile.log");
Boolean pathExists = Files.exists(logRejetPath, new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
if (pathExists) {
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(logRejetPath.toString());
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("test");
attachment.setName("test");
email.attach(attachment);
}
email.send();
I precise email is a MultiPartEmail object created like this:
MultiPartEmail email = new MultiPartEmail();
try {
email.setHostName(config.getSmtpHost());
email.setSmtpPort(Integer.valueOf(config.getSmtpPort()));
if (!config.getSmtpUser().isEmpty()) {
email.setAuthenticator(
new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPwd()));
email.setSSLOnConnect(true);
} else {
email.setSSLOnConnect(false);
}
email.setCharset("utf-8");
email.setFrom("me#me.fr");
email.setSubject("subjectforemail");
email.setContent(this.getMessage(), "text/html");
final String[] destinataires = config.getMailDestinataires().split(";");
for (final String dest : destinataires) {
email.addTo(dest);
}
Every time with these different methods to add an attachment, i receive my email with the message but without the attachment. Every time, variable pathExists is TRUE and every times i have no error.
Thanks for your future answers and help.
EDIT : Solution found by changing this :
MultiPartEmail email = new MultiPartEmail();
by this :
HtmlEmail email = new HtmlEmail();
Solution found by changing this :
MultiPartEmail email = new MultiPartEmail();
by this :
HtmlEmail email = new HtmlEmail();

How to let user click to open the CSV file in browser C# BotFramework SDK3

As the title, I want to let user click to open a file in browser which is created by Bot. I'm using webChat.
The code is what I have tried.
In botframework-emulator, if I click the link, the CSV file will open in the browser.
But in the webChat, it will request user to download, not open in the browser.
var aaa = await GetCSVAttachmentAsync(replymes.ServiceUrl, replymes.Conversation.Id);
foreach(var aa in aaa)
replymes.Attachments.Add(aa);
await context.PostAsync(replymes);
private async Task<IList<Attachment>> GetCSVAttachmentAsync(string serviceUrl, string conversationId)
{
string str = "this is a text CSV";
byte[] array = Encoding.GetEncoding("shift_jis").GetBytes(str);
using (var connector = new ConnectorClient(new Uri(serviceUrl)))
{
var attachments = new Attachments(connector);
var response = await attachments.Client.Conversations.UploadAttachmentAsync(
conversationId,
new AttachmentData
{
Name = "userinfo.csv",
OriginalBase64 = array,
Type = "text/csv"
});
message.Add(new Attachment
{
Name = "userinfo.html",
ContentType = "text/html",
ContentUrl = response.Id
});
return message;
}
}
To solve this problem, I also tried storageV2. But it seems the URI can't be accessed directly.
I still couldn't figure it out without creating a real file.
But instead of using storage V2, I can solve the problem. The thought is as below.
Let the bot create a file.
Upload it to Storage V2 using static website
Send the static website to user.

How do I send a base64 encoded PDF file?

I want my bot to send a PDF file to the user. I have the PDF as a base64 string and tried to send it through an attachment:
Attachment attachment1 = new Attachment();
attachment1.Name = "name.pdf";
attachment1.ContentType = "application/pdf";
attachment1.ContentUrl = "data:application/pdf;base64," + base64String;
var m = context.MakeMessage();
m.Attachments.Add(attachment1);
m.Text = "File";
await context.PostAsync(m);
Within the emulator, it just doesn't work but in the channels Telegram and Facebook (which I need), the bot just outputs an error...
Has someone already succeed in it?
Note: Using an HTTP address works fine, but I need to use the base64 string
As this method in botframework call sendDocument method of Telegram, and this method in its document property get http url or a file_id, so you can't pass base64String to this method as a valid document type.
You can follow the valid type of the document passing into the telegram in this link (also, see the following image).
The pdf file must be embedded resource. Hope it help.
if (this.channelid == "telegram")
{
var url = string.Format("https://api.telegram.org/bot{0}/sendDocument", Settings.tokentelegram);
Assembly _assembly;
Stream file;
using (var form = new MultipartFormDataContent())
{
form.Add(new StringContent(this.chat_id, Encoding.UTF8), "chat_id");
_assembly = Assembly.GetExecutingAssembly();
file = _assembly.GetManifestResourceStream("Namespace.FolderResourses.name.pdf");
form.Add(new StreamContent(file), "document", "name.pdf");
using (var client = new HttpClient())
{
await client.PostAsync(url, form);
}
}
}

How do i display images in Microsoft bot framework with only the base64 encoded string of the image?

i tried the below code, and here is the output i get in emulator
message.Attachments.Add(new Attachment()
{
ContentUrl = $"data:image/jpeg;base64,xxxx"
});
There appears to be a max size for data uri images, however your initial code looks good to me and isn't throwing an explicit internal server error (as it would if the datauri is too large).
I've implemented something similar:
var reply = message.CreateReply("Here's a **datauri image attachment**");
reply.Attachments = new List<Attachment> {
new Attachment()
{
ContentUrl = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAAQABADAREAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAACAUH/8QAJhAAAQMDAwQCAwAAAAAAAAAAAQIDBQQGEQcIEgATISIUMRUjUf/EABYBAQEBAAAAAAAAAAAAAAAAAAMBBP/EAB8RAAICAQQDAAAAAAAAAAAAAAECAAMRBBITIiFB8P/aAAwDAQACEQMRAD8AubjdVbtj5cQFi3tX2lS/ka16Rko9pZqHHfklplgKAylJPNR/vEZPWyvTpUN7jMyK3M21fE03ZLuQ1Gmbyc0j1Dudq7o8RztXFzXEGtacZeQhxipKT7D9qcKUOQ+skfRWKrdqxj71HI4erHME97633Fc+pF10c64pIg7ll6CldoEcHEoTVL7fMZ9se2CPOekdkCiSjIYmLvYvMRdLQPXDG3FGSEzK1iKB4rYCnaan7oVwcCQCHVqGTkkeEefGOgbTtjccyW6sM4QAT//Z",
ContentType = "image/jpg",
Name = "datauri"
}
};
Which results in the emulator showing this image (I need more rep to embed images.. ugh..)
Update: a data uri version of a ~20kb image works just fine, however a data uri version of a ~140kb image fails with a "500 internalservererror" in the emulator. Guess there is a size limit after all..
As such, can you validate that he datauri you're using is a valid image? Can you create a simple html page with an img element, paste in the value in your ContentUrl and see the image in the html page? Or even just paste it into a browser address bar.
When you want to display images you can use markdowns.
var replyMessage = "[ImgName](" + ImagesUrl + ")";
return message.CreateReplyMessage(replyMessage);
Bot Framework Markdown Documentation
================= Convert Base64 string to Image ==========================
public void SaveImage(string base64)
{
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
using (Bitmap bm2 = new Bitmap(ms))
{
bm2.Save("SavingPath" + "ImageName.jpg");
}
}
}
Then you can use the URL.

Replace Image in PDF with another Image pdf box

How to replace Image in PDF with another Image pdf box. How to do that?
I want to change VisualSignature on the pdf with another image.
I get Visual Apereance like that:
PDDocument doc= PDDocument.load(new FileInputStream("c:\\temp\\template.pdf"));
File dir= new File("c:\\temp\\");
Iterator<Entry<COSObjectKey, Long>> xrefEntriesIt =
doc.getDocument().getXrefTable().entrySet().iterator();
while( xrefEntriesIt.hasNext() ) {
COSObject object = doc.getDocument().getObjectFromPool(
xrefEntriesIt.next().getKey() );
if ( object.getDictionaryObject( COSName.SUBTYPE ) == COSName.IMAGE ) {
changeImage( object, doc);
}
}
and method for to change image
private static void changeImage(COSObject obj, PDDocument doc) {
PDXObjectImage imageInPdf =
(PDXObjectImage) PDXObject.createXObject(
(COSStream) obj.getObject());
File inputFile = new File("C:\\temp\\SIGNATURE.jpg");
PDXObjectImage newImage = new PDJpeg(
doc, new FileInputStream(inputFile));
imageInPdf.getCOSStream().replaceWithStream(newImage.getCOSStream());
}
I tested. imageInPdf is rally image from visual appearance of a signed signature field.
now how to remove and add new visual appearance of a signed signature field?
I've just added doc.save(). that's all

Resources