Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to send mails from xyz@anydomain.com to other domains like yahoo,rediff,etc. in my code already an smtp server is declare according our application its named as xyz@abc.co.uk.when i send mails its showing mail send successfully but the mail does not reaching to the user.

C#
for (int i = 0; i < stremail.Length; i++)
          {
              Email email = new Email();
              intuserid = int.Parse(struserid[i]);
              strTo = stremail[i];
              if (txtemailid.Text != string.Empty)
              {
                  strFrom = txtemailid.Text;
              }
              else
              {
                  strFrom = ddlexisting.SelectedItem.Text;
              }
              strSubject = txtcreate.Text;
              int iport = 25;
              strBody = Editor1.Content;

              int intresult = email.SendEmail(strFrom, strTo, strSubject, strBody, iport);
              try
              {
                  if (intresult == 0)
                  {
                      insertsendemaildetail();
                  }
              }
              catch (SmtpException exception)
              {
                  //lblfpError.Text = "Message: " + exception.Message + ", Status Code: " + exception.StatusCode.ToString();
              }
         }
Posted
Updated 16-Apr-12 1:43am
v2
Comments
sravani.v 16-Apr-12 6:54am    
can you share your code?
V. 16-Apr-12 7:44am    
Added code to question in code tags.
[no name] 10-Oct-12 15:41pm    
Nice post really helpfull.

You should be using SmtpMail.Send[^] unless Email.Send is some wrapper you have created. Regardless, these methods only push the email to the SMTP server and does not guarantee delivery. There could be any number of issues preventing actual receipt, bad address, blocked sender, etc.
 
Share this answer
 
Comments
Ramu15 16-Apr-12 8:06am    
It is not showing any error messages
[no name] 16-Apr-12 8:09am    
As long as the objects are valid it will not show any exceptions. That doesn't mean the email was sent by the SMTP server or received by the client. Do some research.
Hi,

You can acheive this by using the system.net. Actually Iwas facing some problem while using system.net

I have searched in the net for 2-3 days and finally I got a solution. I tried system.webmail insted of system.net and it works fine. Then I got to know that my server was not supporting system.net

Thanks
Tapan kumar
 
Share this answer
 
Id did it like this (.Net 4.0):
C#
private bool Send(){
	bool result = false;
	MailMessage mail = new MailMessage();
	try{
		//Attaches email addresses to the MailMessage object
		GetAdressesTo(ref mail); 
		//Attaches email addresses to the MailMessage object
		GetAdressesCc(ref mail); 
		mail.From	= new MailAddress(txtbox_mailfrom.Text);
		mail.Subject	= txtbox_mailsubject.Text;
		mail.Body	= txtbox_mailtext.Text;
		SmtpClient smptclient = new SmtpClient(ConfigurationSettings.GetConfigurationSetting("MailServer"));
		smptclient.Send(mail);
		result = true;
	}			//end try
	catch(Exception ex){
		//Do something with exception here
	}			//end catch
	finally{
		mail.Dispose();	
	}					//end finally
	return result;
}


Hope this helps.
 
Share this answer
 
v2
Comments
[no name] 16-Apr-12 8:12am    
And how does this answer the question? You have just provided useless and confusing clutter with functionality the OP is not using and didn't ask for.
V. 16-Apr-12 8:25am    
He asked how to send a mail via SMTP, which is what I did. I admit I could have cleaned it a little more, but the code is correct and working. I'm not perfect, just trying to help.
V. 16-Apr-12 8:32am    
There, I cleaned it a little, it uses the same object you recommend so it shouldn't be hard for the OP to understand.
[no name] 16-Apr-12 8:43am    
It is not necessary to create your own element in config file for MailServer settings. It already exists. http://msdn.microsoft.com/en-us/library/w355a94k(v=vs.90).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900