Sending Mail on Server Problem

Posted by Ganeshjoshi under ASP.NET on 7/8/2013 | Points: 10 | Views : 678 | Status : [Member] | Replies : 1
Hi All,
in my application i want's to send a mail with excel attachment, i host my application on server whenever we logged on into the server the mail send properly but whatever
when we are not logged on into server then my mail process not working...
it want's to logged on to server for sending a mail .
how to send a mail without logged on to server.

My Code is below

string OutputFilePath = string.Format(Path, "ExcelFile\\" + String.Format("{0:yyyyMMdd}", oDMREntity.ForTheDay) + ".xls");
FileStream oFS = new FileStream(OutputFilePath, FileMode.Open);
MailMessage mailMsg = new MailMessage();
MailAddress mailAdd;

mailAdd = new MailAddress(ConfigurationManager.AppSettings["FromMail"]);
mailMsg.From = mailAdd;
mailMsg.To.Add(ConfigurationManager.AppSettings["DMRToMail"]);
mailMsg.CC.Add(ConfigurationManager.AppSettings["DMRCcMail"]);
mailMsg.Bcc.Add(ConfigurationManager.AppSettings["DMRBccMail"]);

Attachment data = new Attachment(oFS, Path.GetFileName(OutputFilePath));
mailMsg.Attachments.Add(data);
mailMsg.Subject = "Daily Maintenance Report | " + String.Format("{0:MMMM d, yyyy}", oDMREntity.ForTheDay);
mailMsg.Body = MailContent;
mailMsg.IsBodyHtml = true;
SmtpClient mSMTPClient = new SmtpClient();
mSMTPClient.Send(mailMsg);




Responses

Posted by: aswinialuri-19361 on: 7/8/2013 [Member] Starter | Points: 25

Up
0
Down
hi
try this code
it might will be helpful to you
using system.net.mail;


MailMessage msg = new MailMessage("aswinialuri@gmail.com", txt1_to.Text);


msg.IsBodyHtml = true;
msg.Subject=txt_sub.Text.ToString();
msg.Body=txt_body.Text.ToString();
if(fle1.HasFile)
{
msg.Attachments.Add(new Attachment(fle1.PostedFile.InputStream, fle1.FileName));
}
NetworkCredential nc = new NetworkCredential("aswinialuri@gmail.com", "yourpwd@");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = nc;
smtp.Send(msg);


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Ganeshjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response