converting base64 string to attachment c# -


i trying convert base64 string(image/svg+xml) image attachment in c#, trying convert string image(png), save it, attach mail. tried send embedded image in mail didn't work because not client apps support embedded images in mail. what data uri support in major email client software? have convert file(png,pdf...), attach it, , send it. code send embedded image :

public actionresult sendmail(string data , string mailstosend) {               try     {         string[] mailsarr = mailstosend.split('/');         mailmessage mailmsg = new mailmessage();         smtpclient client = new smtpclient();         var imagedata = convert.frombase64string(data);         var contentid = guid.newguid().tostring();         var linkedresource = new linkedresource(new memorystream(imagedata), "image/svg+xml");         linkedresource.contentid = contentid;         linkedresource.transferencoding = transferencoding.base64;         var body = string.format("<img src=\"cid:{0}\" />", contentid);         var htmlview = alternateview.createalternateviewfromstring(body, null, "text/html");         htmlview.linkedresources.add(linkedresource);         mailmsg.alternateviews.add(htmlview);            client.port = 587;         client.enablessl = true;         client.host = "smtp.gmail.com";         client.timeout = 60000;         client.deliverymethod = smtpdeliverymethod.network;         client.usedefaultcredentials = false;         client.credentials = new networkcredential("", "");                      mailmsg.from = new mailaddress("");         (int = 0; < mailsarr.length; i++)         {             mailmsg.to.add(new mailaddress(mailsarr[i]));         }         mailmsg.to.add(new mailaddress(""));         mailmsg.subject = "test";         mailmsg.isbodyhtml = true;         mailmsg.body = body;         client.send(mailmsg);     }     catch(exception ex)     {      }     return null;         } 

i trying convert base64 string image :

private void savebytearrayasimage(string fulloutputpath, string base64string) {     byte[] bytes = convert.frombase64string(base64string);     system.drawing.image image;     using (memorystream ms = new memorystream(bytes))     {         image = system.drawing.image.fromstream(ms);     }      image.save(fulloutputpath+".png"); } 

however function throws exception

parameter not valid

i tried replace base64 string black pixel base64 string , worked!

so how can convert base64 string (image/svg+xml) image (png format) , attach mail?

thank you.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -