ASP.net 1.1 smtp发邮件
Sent email by System.Web.Mail.MailMessage in c#
-handiz@hotmail.com
-----------------------------------------------------
public void SendMail(string recp, string title, string msg)
{
//define Mail message
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
mail.To = recp;
mail.From = System.Configuration.ConfigurationSettings.AppSettings["MailSender"];
mail.Subject = title;
mail.Body = msg;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","username"); //your smtp username
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","password"); //your smtp password
System.Web.Mail.SmtpMail.SmtpServer = "smtp.mail"; //your smtp server address
System.Web.Mail.SmtpMail.Send(mail);
}
ASP.net 2.0 smtp发邮件:
Date:2006-11-08, Title:(DotNet) How to sent email from C#2.0
(DotNet) How to sent email from C#2.0
handiz@hotmail.com
-------------------
static public void SendMail(string recp, string title, string msg)
{
//sender
string strFrom = System.Configuration.ConfigurationManager.AppSettings["MailSender"];
//smtp server password
string strPass = System.Configuration.ConfigurationManager.AppSettings["MailPassword"];
//mail object
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(strFrom,recp);
mail.Subject = title;
mail.Body = msg;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.UTF8;
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
//smtp serveraddress
smtpClient.Host = System.Configuration.ConfigurationManager.AppSettings["MailSmtp"];
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(strFrom, strPass);
//smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Send(mail);
}
合并/分割 TIF 图片:
Title:Generate multipage TIF and split multipage TIF in C#
Generate multipage TIF and split multipage TIF in C#
MSN: handiz@hotmail.com
Email: handiz@gmail.com
----------------
Using the TifPrint.dll
(download at: http://www.diaries.cn/myworks/MSDotNet/Class/TifPrint/BIN/tifprint.zip)
//split the multiple page TIF file into single file
SplitTif(strFilename, strTargetFolder)
//Combine the Files(can be jpg, bmp, tif, png, gif) into one multipage Tif file
CombineTif(string[] InputFilenames, string OutputFilename)
----------------
/// <summary>
/// Combine some file into 1 tif multipage file
/// if black and write image, we use CCITT4 compression
/// else we use the LZW compression
/// </summary>
/// <param name="InputFilenames">the files to be combined, canbe (bmp, jpg, gif, png, tif)</param>
/// <param name="OutputFilename">the output filename</param>
public static void CombineTif(string[] InputFilenames, string OutputFilename)
{
//get ImageCodecInfo, generate tif format
ImageCodecInfo info = null;
foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
{
if (ice.MimeType == "image/tiff")
{
info = ice;
break;
}
}
/*
* define the encoderparameter,
* when the 1st page, will be EncoderValue.MultiFrame.
* when the other pages, will be EncoderValue.FrameDimensionPage.
* when all pages saved, will be the EncoderValue.Flush.
*/
EncoderParameters ep = new EncoderParameters(2);
/*
* when the 1st file, 1st frame, will be true.
* from the 1st file, 2nd frame, will be false.
*/
bool b11 = true;
Image img =null;
//create a image instance from the 1st image
for (int nLoopfile = 0; nLoopfile < InputFilenames.Length; nLoopfile ++)
{
//get image from src file
Image img_src = Image.FromFile(InputFilenames[nLoopfile]);
Guid guid = img_src.FrameDimensionsList[0];
System.Drawing.Imaging.FrameDimension dimension = new
System.Drawing.Imaging.FrameDimension(guid);
//get the frames from src file
for (int nLoopFrame =0; nLoopFrame < img_src.GetFrameCount(dimension); nLoopFrame ++)
{
img_src.SelectActiveFrame(dimension, nLoopFrame);
/*
* if black and write image, we use CCITT4 compression
* else we use the LZW compression
*/
if (img_src.PixelFormat == PixelFormat.Format1bppIndexed)
{
ep.Param[0] = new EncoderParameter(Encoder.Compression, Convert.ToInt32(EncoderValue.CompressionCCITT4));
}
else
{
ep.Param[0] = new EncoderParameter(Encoder.Compression, Convert.ToInt32(EncoderValue.CompressionLZW));
}
if (b11)
{
//1st file, 1st frame, create the master image
img = img_src;
ep.Param[1] = new EncoderParameter(Encoder.SaveFlag, Convert.ToInt32(EncoderValue.MultiFrame));
img.Save(OutputFilename, info, ep);
b11 = false;
continue;
}
ep.Param[1] = new EncoderParameter(Encoder.SaveFlag, Convert.ToInt32(EncoderValue.FrameDimensionPage));
img.SaveAdd(img_src, ep);
}
}
ep.Param[1] = new EncoderParameter(Encoder.SaveFlag, Convert.ToInt32(EncoderValue.Flush));
img.SaveAdd(ep);
}
====================
Title:(DotNet) How to split multiple page TIF to single file in c#
(DotNet) How to split multiple page TIF to single file in c#
handiz@hotmail.com
---------------------------------------------------------
//This function will split a TIF file into sigle file, and put them
//into strTargerFolder.
public static void SplitTIF(string strFilename, string strTargetFolder)
{
Image img = Image.FromFile(strFilename);
Guid guid = img.FrameDimensionsList[0];
System.Drawing.Imaging.FrameDimension dimension = new
System.Drawing.Imaging.FrameDimension(guid);
int nTotFrame = img.GetFrameCount(dimension);
//save all frame
int nLoop =0;
for (nLoop = 0; nLoop<nTotFrame; nLoop++)
{
img.SelectActiveFrame(dimension, nLoop);
img.Save(strTargetFolder + "\\"+nLoop.ToString() + ".tif",
System.Drawing.Imaging.ImageFormat.Tiff);
}
}
打印 TIF 图片:
Title:4 steps to Print Tif in c#
4 steps to Print Tif in c#
handiz@hotmail.com
----------------
Using the TifPrint.dll
(download at: http://www.diaries.cn/myworks/MSDotNet/Class/TifPrint/BIN/TifPrint.dll)
//1. create instance of TifPrint
TifPrint tp = new TifPrint();
//2. add tif files to printing list:
tp.AddFile(@"c:\1.tif");
tp.AddFile(@"c:\2.tif");
...
//3. show printing dialog or not
tp.ShowDialog = true;
//4. Print
tp.Print();
Other functions:
ClearFile() - remove all files from printing list
GetPageCount() - return the total page number of printing list
SplitTif(strFilename, strTargetFolder) - split the multiple page TIF file into single file
C#将网页保存为mht 文件
1. 增加 COM Reference
Microsoft CDO for Windows 2000 Library (C:\WINDOWS\System32\cdosys.dll)
2. 程序:
CDO.Message msg = new CDO.MessageClass();
CDO.Configuration cfg = new CDO.ConfigurationClass();
msg.Configuration = cfg;
msg.CreateMHTMLBody("http://www.sina.com.cn", CDO.CdoMHTMLFlags.cdoSuppressAll, "", "");
msg.GetStream().SaveToFile("c:\\a.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);