TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kiran kumar
NA
8
0
send mail to gmail acoount
May 21 2010 8:12 AM
Hi this is kiran .. i try the code for send email ..but i get error .please solve this code
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(Textfrom.Text, Textto.Text);
mail.To.Add(Textto.Text);
mail.From = new MailAddress(Textfrom.Text, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = txtsubject.Text;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = bodytxt.Text;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
if (FileUpload1.HasFile)
{
// string PhysicalPath = "C:\\Documents and Settings\\Administrator\\Desktop\\";
string fileName = FileUpload1.PostedFile.FileName;
FileUpload1.PostedFile.SaveAs(fileName);
Attachment data = new Attachment( fileName);
mail.Attachments.Add(data);
}
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(Textfrom.Text, "9966794757");
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layers
restxt.Text = "Send Mail";
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage);
}
But i got this error
Untitled Page
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message
Reply
Answers (
1
)
Windows authentication
VC++ equivalent of C# keyword params