Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's rather simple to do using system CDO dll. I already has a working prototype, just drop a mail to site2email@gmail.com and you will receive an answer with embedded webpage (in case of url was provided in subject) or attached web archive (mht file with all resources included) in case of url sent in the mail's body. Here is a quick and dirty code snippet you can play with:</p> <pre><code> private void ConvertAndSend(string emailTo,Uri url) { try { string mimeType; string charset; if (NetworkUtils.UrlExists(url.AbsoluteUri,out mimeType,out charset)) { if (mimeType.Equals("text/html",StringComparison.OrdinalIgnoreCase)) SendUrlToEmail(url.AbsoluteUri,emailTo,charset); else { string fileName = Path.GetFileName(url.AbsoluteUri); string extension = GetExtensionByMimeType(mimeType); if (String.IsNullOrEmpty(fileName) || fileName.Length &gt; 200) fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); if (!Path.GetExtension(fileName).Equals(extension ,StringComparison.OrdinalIgnoreCase)) fileName += extension; string tempFolder = Path.Combine(Server.MapPath("App_Data") ,"TempFiles"); if (!Directory.Exists(tempFolder)) Directory.CreateDirectory(tempFolder); fileName = Path.Combine(tempFolder,fileName); new WebClient().DownloadFile(url.AbsoluteUri,fileName); SendMessage(emailTo,url.AbsoluteUri,Path.GetFileName(fileName),fileName); } } else { throw new WebException("Requiested address is not available at the moment."); } } catch (Exception ex) { SendMessage(emailTo,url.AbsoluteUri,ex.Message,null); } } public void SendUrlToEmail(string url ,string emailTo ,string charset) { Encoding encFrom; try { encFrom = Encoding.GetEncoding(charset); } catch { encFrom = Encoding.UTF8; } CDO.Message msg = null; ADODB.Stream stm = null; try { msg = new CDO.MessageClass(); msg.MimeFormatted = true; msg.CreateMHTMLBody(url ,CDO.CdoMHTMLFlags.cdoSuppressNone ,string.Empty ,string.Empty); //msg.HTMLBodyPart.Fields["urn:schemas:mailheader:Content-Language"].Value = "ru"; msg.HTMLBodyPart.Fields["urn:schemas:mailheader:charset"].Value = "Cp" + encFrom.CodePage; msg.HTMLBodyPart.Fields["urn:schemas:mailheader:content-type"].Value = "text/html; charset=" + charset; msg.HTMLBodyPart.Fields.Update(); msg.HTMLBody = documentBody; msg.Subject = url; msg.From = Params.Username; msg.To = emailTo; msg.Configuration.Fields[GmailMessage.SMTP_SERVER].Value = SmtpServer; msg.Configuration.Fields[GmailMessage.SEND_USING].Value = 2; msg.Configuration.Fields.Update(); msg.Send(); } finally { if (stm != null) { stm.Close(); Marshal.ReleaseComObject(stm); } if (msg != null) Marshal.ReleaseComObject(msg); } } </code></pre> <p>NetworkUtils.UrlExists is a small method that send HEAD and then if it fail GET request to determine type and encoding of the content.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload