How to ensure the mail is sent or not in C#.Net ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varunkumarid
    New Member
    • Aug 2008
    • 40

    How to ensure the mail is sent or not in C#.Net ?

    Hi to Everybody,

    I have use the C#.net for send the E-mail as follows

    MailMessage omsg = new MailMessage();
    omsg.From = new MailAddress("sa thiy.03@gmail.c om");
    omsg.To.Add(new MailAddress(txt Email.Text));
    //omsg.Subject = txtSubject.Text ;
    //omsg.Body = txtContent.Text ;

    if (txtSubject.Tex t.Trim() != "")
    {
    omsg.Subject = txtSubject.Text .Trim();
    }
    else
    {
    omsg.Subject = "No Subject";
    }
    //omsg.IsBodyHtml = true;
    omsg.Body = txtContent.Text .Trim();
    omsg.Attachment s.Add(new Attachment("d://download.txt")) ;
    SmtpClient client = new SmtpClient("192 .168.1.5", 25);
    client.Delivery Method = SmtpDeliveryMet hod.Network;
    client.Credenti als = System.Net.Cred entialCache.Def aultNetworkCred entials;
    //client.Host = ;
    try
    {
    client.Send(oms g);
    }
    catch (SmtpFailedReci pientsException ex)
    {
    for (int i = 0; i < ex.InnerExcepti ons.Length; i++)
    {
    Response.Write( ex.InnerExcepti ons[i].FailedRecipien t.ToString());
    }
    }

    If i send the mail with attach file it did not receive but it received without attachment file.

    Please give me the solution to send e-mail with attached file.

    Thanks
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    1) please wrap your code in [noparse][code] your code here [/code] tags, as you were asked to when you created the message.

    2) You are correctly adding the attachment. It sounds like the attachment was stripped out by the the SMTP sender, or the receiver's email client. That happens. Sometimes the receiver has a limit on the size of the attachment. Or a limit on the total space they can use for attachments. Or virus protection. Or the company doesn't allow attachments of a certain extension.

    3) Have you tried following the example on the MSDN for creating an Attachment class object out of your file? Following the directions does wonders.
    [url]http://msdn.microsoft. com/en-us/library/system.net.mail .attachment.asp x[/url]

    Comment

    Working...