I created a website and uploading into my hosting server. In that sending mail along with attachment on my hosting server. but i getting following error;
Parser Error Message: This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using
Source Error:
Line 25: during development. |
Let me cleared my side what i done;
Am using VS 2008, asp.net 2.0 and sending mail using System.net.mail name space. here my code:
using
System.Net.Mail;
MailMessage objEmail = new
MailMessage();
objEmail.To.Add(txtTo.Text.ToString());
objEmail.From = new MailAddress("[email protected]");
objEmail.Subject = "User
Account Details";
objEmail.Body = "Your User
Account was created";
objEmail.Priority = System.Net.Mail.MailPriority.High;
objEmail.IsBodyHtml = true;
string
strFileName = null;
if
(FileUpload1.PostedFile != null)
{
HttpPostedFile attFile = FileUpload1.PostedFile;
int
attachFileLength = attFile.ContentLength;
if
(attachFileLength > 0)
{
strFileName =
FileUpload1.PostedFile.FileName;
Attachment attFilename = new Attachment(strFileName);
objEmail.Attachments.Add(attFilename);
}
}
SmtpClient smtpclient = new
SmtpClient();
try
{
smtpclient.Send(objEmail);
Response.Write("successfully
sent");
}
catch
(Exception
ex)
{
Response.Write("send
failure:" + ex.ToString());
}
My webconfig setting:
...
...
...
I checked in localhost its working fine and also on my server mail was going successfully but only thing is mail along with attachment is getting problems. please help me. its to urgent
Thanks in advance
Rajiv
Abhimanyu K VatsaPosted Jun 14, 2010, 4:17 AM
For emailing no need to specify the trust level. If this is only the cause of your project then you simply erase it. Brother in the configuration file you have used www.computertekk.com as host name that is highly wrong. There could be only IP address of your hosting sever or the smtp address like "smtp.gmail.com".
<system.net>
<mailSettings>
<smtp>
<network
host="smtp.domainname.com"
userName="[email protected]"
password="xxxxxxxxx"
port="25"/>
smtp>
mailSettings>
system.net>
Here is a link of the same project and also tested on hosting server ok....
http://www.vbdotnetheaven.com/UploadFile/abhikumarvatsa/1534/Default.aspx
I hope my post will help you. Take care
tekkPosted Jun 16, 2010, 9:26 AM
Thanks for information
Abhimanyu K VatsaPosted Jun 16, 2010, 9:22 AM
one thing is very important to be considered is
if u are using your gmail credential then your project will run on each and every mail servers.
but if u are using ur own (i mean shared mail server hosting) and getting any error on any particular email server (like as u faced with yahoo not with gmail) means your hosting server provider has no compatibility with yahoo mail server. because of some charges (cost) many hosting mail servers has no certification or contract to user other mail servers like yahoo, gmail. your mail server has contract with gmail but not with yahoo.
Good Luck
tekkPosted Jun 16, 2010, 3:55 AM
I followed what you suggested and little bit code modification in your code. It really helped me for getting perfect results.Thanks for your guidance.
here my modification code:
MailMessage objEmail = new MailMessage();
objEmail.To.Add(txtTo.Text.ToString());
objEmail.From = new MailAddress("[email protected]");
objEmail.Subject = "User Account Details";
objEmail.Body = " Your User Account was created";
string strFileName = null;
HttpPostedFile attFile = FileUpload1.PostedFile;
int attachFileLength = attFile.ContentLength;
if (attachFileLength > 0)
{
strFileName = FileUpload1.PostedFile.FileName;
Attachment attFilename = new Attachment(FileUpload1.PostedFile.InputStream, strFileName);
objEmail.Attachments.Add(attFilename);
}
SmtpClient smtpclient = new SmtpClient();
try
{
smtpclient.Send(objEmail);
Response.Write("successfully sent");
}
Thanks,
Tekk
tekkPosted Jun 14, 2010, 10:21 AM
Thanks for reply,
What you suggest i followed your method. Mail sent successfully with attachment file. but problem is,
1) In Gmail, mail getting attachment file with also displayed attachment file content in body of mail,
2)In Yahoo, Mail getting but attachment file content displayed in body itself, not showing attachment file in mail
here my code:
MailMessage objEmail = new MailMessage();
objEmail.To.Add(txtTo.Text.ToString());
objEmail.From = new MailAddress("[email protected]");
objEmail.Subject = "User Account Details";
objEmail.Body = txtName.Text.ToString() + "' Your User Account was created";
if (FileUpload1.HasFile == true)
{
FileUpload fu = FileUpload1;
string ct = fu.PostedFile.ContentType;
string fn = fu.PostedFile.FileName;
int c = fn.LastIndexOf(@"\");
fn = fn.Substring(c + 1);
Attachment attach = new Attachment(FileUpload1.PostedFile.InputStream, fn, ct);
objEmail.Attachments.Add(attach);
}
SmtpClient smtpclient = new SmtpClient();
try
{
smtpclient.Send(objEmail);
Response.Write("successfully sent");
}
catch (Exception ex)
{
Response.Write("send failure:" + ex.ToString());
}
Webconfig setting:
please help me,
Thanks in advance
Rajiv