Sr. Software Engineer
Wednesday, February 11, 2015
Monday, February 9, 2015
SendEmail
public void SendEmail(string email, string body, string subject, string sender)
{
if (email.Trim() != "" && email.Trim() != " ")
{
if (isEmail(email))
{
try
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
if (sender != "")
{
message.From = new MailAddress(sender);
}
else
{
message.From = new MailAddress("serviceteam@julyservices.com");
}
var emails = email.Split(new Char[] { ',', ';' });
foreach (var to in emails)
{
if (!String.IsNullOrEmpty(to))
message.To.Add(new MailAddress(to));
}
message.To.Add(new MailAddress(email));
message.Subject = subject;
message.Body = body;
message.Priority = System.Net.Mail.MailPriority.High;
message.IsBodyHtml = true;
//SmtpClient smtpClient = new SmtpClient("mail.texaspension.com");
//smtpClient.UseDefaultCredentials = true;
System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "mail.julyservices.com";
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
smtpClient.Credentials = SMTPUserInfo;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
}
catch (Exception ex)
{
throw ex;
}
}
}
}
{
if (email.Trim() != "" && email.Trim() != " ")
{
if (isEmail(email))
{
try
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
if (sender != "")
{
message.From = new MailAddress(sender);
}
else
{
message.From = new MailAddress("serviceteam@julyservices.com");
}
var emails = email.Split(new Char[] { ',', ';' });
foreach (var to in emails)
{
if (!String.IsNullOrEmpty(to))
message.To.Add(new MailAddress(to));
}
message.To.Add(new MailAddress(email));
message.Subject = subject;
message.Body = body;
message.Priority = System.Net.Mail.MailPriority.High;
message.IsBodyHtml = true;
//SmtpClient smtpClient = new SmtpClient("mail.texaspension.com");
//smtpClient.UseDefaultCredentials = true;
System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "mail.julyservices.com";
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
smtpClient.Credentials = SMTPUserInfo;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Upload a file in ASP.NET
http://www.codeproject.com/Articles/1757/File-Upload-with-ASP-NET
public string UploadPersonalFile(HttpPostedFile myFile, string ContactID)
{
proposalcenterfunctions proposalfunctions = new proposalcenterfunctions();
this.strRootFilePath = @"" + ConfigurationManager.AppSettings["CensusDataFilesParentDirectory"];
ProjectPath = "Contacts\\" + ContactID;
PhysicalDirPath = strRootFilePath + ProjectPath;
DirectoryInfo clientDir = new DirectoryInfo(PhysicalDirPath);
if (clientDir.Exists == false)
{
clientDir.Create();
}
// Get size of uploaded file
int nFileLen = myFile.ContentLength;
try
{
// make sure the size of the file is > 0
if (nFileLen > 0)
{
// Allocate a buffer for reading of the file
byte[] myData = new byte[nFileLen];
// Read uploaded file from the Stream
myFile.InputStream.Read(myData, 0, nFileLen);
// Create a name for the file to store
string strFilename = Path.GetFileName(myFile.FileName);
string Extension = strFilename.Remove(0, strFilename.LastIndexOf('.'));
string fileName = strFilename.Substring(0, strFilename.Length - Extension.Length);
var dateTime = DateTime.Now.ToString("MMddyy_hh-mm-ss");
strFilename = fileName + "_" + dateTime + Extension;
strFullFilePath = PhysicalDirPath + "\\" + strFilename;
proposalfunctions.WriteToFile(strFullFilePath, ref myData);
}
else
{
strFullFilePath = "";
}
}
catch (Exception ex)
{
ExceptionLogger.WriteLog(ex, "UploadFile");
}
return strFullFilePath;
}
public void WriteToFile(string strPath, ref byte[] Buffer)
{
FileStream stream = new FileStream(strPath, FileMode.Create);
stream.Write(Buffer, 0, Buffer.Length);
stream.Close();
}
public string UploadPersonalFile(HttpPostedFile myFile, string ContactID)
{
proposalcenterfunctions proposalfunctions = new proposalcenterfunctions();
this.strRootFilePath = @"" + ConfigurationManager.AppSettings["CensusDataFilesParentDirectory"];
ProjectPath = "Contacts\\" + ContactID;
PhysicalDirPath = strRootFilePath + ProjectPath;
DirectoryInfo clientDir = new DirectoryInfo(PhysicalDirPath);
if (clientDir.Exists == false)
{
clientDir.Create();
}
// Get size of uploaded file
int nFileLen = myFile.ContentLength;
try
{
// make sure the size of the file is > 0
if (nFileLen > 0)
{
// Allocate a buffer for reading of the file
byte[] myData = new byte[nFileLen];
// Read uploaded file from the Stream
myFile.InputStream.Read(myData, 0, nFileLen);
// Create a name for the file to store
string strFilename = Path.GetFileName(myFile.FileName);
string Extension = strFilename.Remove(0, strFilename.LastIndexOf('.'));
string fileName = strFilename.Substring(0, strFilename.Length - Extension.Length);
var dateTime = DateTime.Now.ToString("MMddyy_hh-mm-ss");
strFilename = fileName + "_" + dateTime + Extension;
strFullFilePath = PhysicalDirPath + "\\" + strFilename;
proposalfunctions.WriteToFile(strFullFilePath, ref myData);
}
else
{
strFullFilePath = "";
}
}
catch (Exception ex)
{
ExceptionLogger.WriteLog(ex, "UploadFile");
}
return strFullFilePath;
}
public void WriteToFile(string strPath, ref byte[] Buffer)
{
FileStream stream = new FileStream(strPath, FileMode.Create);
stream.Write(Buffer, 0, Buffer.Length);
stream.Close();
}
Subscribe to:
Posts (Atom)