Error on sending email

Discussion in 'C#' started by bkasp, Dec 1, 2008.

  1. #1
    Hi,

    I have written a code for sending email as follows:

    protected void Button1_Click(object sender, EventArgs e)

    {
    MailMessage mailMSG = new MailMessage("abc@domain.com", "def@domain.com");
    mailMSG.Subject = "TEST";
    mailMSG.Body = "this is for test";
    SmtpClient smtp = new SmtpClient();
    System.Net.NetworkCredential basicAuthenicationInfo = new System.Net.NetworkCredential("username", "password");
    smtp.Host = "mailhost.domain.com";
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = basicAuthenicationInfo;
    smtp.Send(mailMSG);
    }

    it works properly on local server. However, after deployment on main server I get this error :"Failure in sending email:System.Web.HttpException: At least one of the From or Sender fields is required, and neither was found ...................."

    Could you please tell me what is the problem.
     
    bkasp, Dec 1, 2008 IP
  2. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Self explanatory error. Add From/To

    e.g.

    MailMessage mailMSG = new MailMessage();
    mailMSG.To.Add(new MailAddress("abc@domain.com"));
    mailMSG.From = new MailAddress("def@domain.com");
    etc.

    Welcome to the forum :) www.vbisbetter.com
     
    yugolancer, Dec 3, 2008 IP
  3. mpatel

    mpatel Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    chek it it will realy help full for sedning email in asp.net


    Dim frm As String = "from@my.com"

    Dim mTo As String = "to@gmail.com"

    Dim subject As String = "Email"

    Dim msgtext As String = "This is my personal websites good na"

    Dim msg As New Net.Mail.MailMessage(frm, mTo, subject, msgtext)

    'msg.Attachments.Add(New System.Net.Mail.Attachment(FileUpload1.PostedFile.FileName))

    Dim strName As String = FileUpload1.PostedFile.FileName
     
    mpatel, Dec 24, 2008 IP