[code]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Calling the function SendMail
Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body"));
}
public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.server.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");
smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}
}
[/code]
--
Thanks and Regards
Meetu Choudhary
Dear meetu,
ReplyDeleteThis is code is working fine.
But i am able to send email to our network when ever i am trying to send mail to outside network it is giving error message
"System.Net.Mail.SmtpFailedRecipientsException: Unable to send to all recipients. ---> System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at _Default.SendMail(String toList, String from, String ccList, String subject, String body) in c:\Documents and Settings\SUNIL\My Documents\Visual Studio 2005\WebSites\SendMail\Default.aspx.cs:line 68}
My code is here
try
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("SenderEmailAddress");
mail.From = new MailAddress("Mycompanydomain", "TEST MAIL");
mail.Subject = Subject.Text;
string Body = Bodymsg.Text;
mail.Body = Body;
mail.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient("mailserver", 587);
smtp.Credentials = new System.Net.NetworkCredential("userID", "password");
smtp.EnableSsl = true;
smtp.Send(mail);
lblTxt.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblTxt.Text = "Send Email Failed. " + ex.Message;
}
Hello Meetu,
ReplyDeleteThanks for your post. It help me a lot. but i have to make an interesting functionality in my project. I have to send attachment to the person whom i want to mail. but have to provide security when the user clicked on attachment. before this it asked about password. if password is correct then only file has been open.
I have searched it on google. but i din't get.
Thanks in advance
Omkar.
Hi ,
ReplyDeletesending emails i got this error.could you help me please.
Server Error in '/SendEmail' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /SendEmail/query_submitted.aspx
Thank you,
Kumari.
Hi Siva Kumarui..
ReplyDeleteThis is not the error of the mail. its like in your application the page url you specified is not the correct one it is not redirecting to the url specified by you the reason may be the page does not exist on that location
Hi Meetu Choudhary,
ReplyDeleteThank you very much ,i would try again. I got this error Failure sending email.
WCF how to starting could you help me step wise.
Thank you.
Hello Siva Kumari
ReplyDeletesure I will Help You Can you tell me The excerpt of what you are doing so that i may help you in rectifying the error
Hello Siva Kumari
ReplyDeletecheck this article also may be of some help
http://aspnetbymeetu.blogspot.com/2009/09/uri-format-not-supported.html
Hello Meetu Choudhary,
ReplyDeleteThank you very much for helping.just I got the .net training i am looking for the job i don't know WCF and XSLT in interview they are
asking could you help me.
Thank you.
Hello Siva Kumari
ReplyDeleteCheck these sites for preparation.
http://www.msdotnetmentor.com/
and there
http://interview.msdotnetheaven.com/
Hi Meetu Choudhary,
ReplyDeleteCould you send the link for me about TFS.How to create.How to use in real project.
Thank you ,
Kumari.
Check this may be helpful. this is mostly implemented in the office itself.
ReplyDeletehttp://msdn.microsoft.com/en-us/vstudio/ff637362.aspx
Dear Madam,
ReplyDeletei just refer your code for sending Email
But i can't do that.
from my application i want to send mail and my ISP at remote place i have all credentials information but still i am unable to send it.
Can you help me out?
Best Regards,
Anup Shah
Hi Mr Shah !
ReplyDeleteit would be good if you can tell me what exact error you are getting. As ISP being at remote does not affect the process of sending mail as in the above example i have used my gmail account. the problem can be the port no. or it is allowed or open on your computer
hi mam,
ReplyDeletecan u help me to study on asp dot net using c#,any sites or can u teach me this please............i'm waiting 4 ur reply mam.................
Hi Priya sure you can learn form http://www.asp.net/web-pages
ReplyDeleteand if you have any queries then you can ask them in my forums as well http://www.jaipurmentor.com/jaipurmentor-forum.html
Thanks
i have got this below error.Please help me
ReplyDeleteFailure sending mail.