You must Sign In to post a response.
  • Category: ASP.NET

    Problem on Sending Mail on Live

    Hi Developers ,

    I have a mail function in my code mail is sends Successfully on Localhost.
    But the same code does not working Exactly on live(when host to our server).
    Mails sends only for Gmail account(paulcse@gmail.com).
    Does not send yahoo, etc(rosepaulcse13@yahoo.com).
    My Code is below,

    public void EmailSend(string frmID, string frmName, string toID, string subMsg, String BodyMsg, bool status)
    {
    try
    {
    SmtpClient smtpclient = new SmtpClient();
    MailMessage message = new MailMessage();
    MailAddress fromAddress = new MailAddress("labmateasia16@gmail.com", "labmateasia16@gmail.com");
    smtpclient.Host = "smtp.gmail.com";
    smtpclient.Port = 587;
    message.From = fromAddress;
    message.To.Add(toID);
    message.Subject = subMsg;
    message.Body = BodyMsg;
    message.BodyEncoding = System.Text.Encoding.ASCII;
    message.IsBodyHtml = status;
    message.Priority = MailPriority.High;
    NetworkCredential ocredential = new NetworkCredential("donotreply00@gmail.com", "12345");
    smtpclient.EnableSsl=true;
    smtpclient.UseDefaultCredentials = false;
    smtpclient.Credentials = ocredential;
    smtpclient.Send(message);
    }
    catch { }
    }

    in Live i have changed below lines

    smtpclient.EnableSsl=false ;
    smtpclient.UseDefaultCredentials =true ;

    Any possible to rectify this error. help me friends

    Thanking you
    Paul.S
  • #767264
    what SMTP address you are providing for sending mail to Yahoo
    for yahoo the smtp should be 'smtp.mail.yahoo.com'
    look at below code for sending mail to yahoo mail

    using System.Net;
    using System.Net.Mail;

    string smtpAddress = "smtp.mail.yahoo.com";
    int portNumber = 587;
    bool enableSSL = true;

    string emailFrom = "email@yahoo.com";
    string password = "abcdefg";
    string emailTo = "someone@domain.com";
    string subject = "Hello";
    string body = "Hello, I'm just writing this to say Hi!";

    using (MailMessage mail = new MailMessage())
    {
    mail.From = new MailAddress(emailFrom);
    mail.To.Add(emailTo);
    mail.Subject = subject;
    mail.Body = body;
    mail.IsBodyHtml = true;
    // Can set to false, if you are sending pure text.

    mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
    mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));

    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
    {
    smtp.Credentials = new NetworkCredential(emailFrom, password);
    smtp.EnableSsl = enableSSL;
    smtp.Send(mail);
    }
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767268
    Thanks mr.Prasad.

    Mail is sending local is fine.
    in live it does not sent to any mail ids with default credential.(smtp.gmail.com, 587)

    so am using my Office server credentials(198.162.1.100,25)
    in this credentials mail sent only for gmail and yahoo ids.(ex:paul@gmail.com,Paul@yahoo.com).
    if i give email id like donotreply@admin.labmateasia.net or info@test.com na mail does not sent.

    now this is my problem. how i am solve this problem .

    if i use Default Credentials (smtp.gmail.com,587) na
    how am using it hosting on Live.
    how am sent mail to all type of mail accounts using Default Credentials (smtp.gmail.com,587) on live

    Paul.S

  • #767280
    Hi,
    If you are using SMTP as 'smtp.gmail.com' then you need to provide your Gmail emaiId and pwd in credentials.
    For 'smtp.mail.yahoo.com' you need to provide your Yahoo emaiId and pwd in credentials.
    For 'smtp.rediffmail.com' you need to provide your Rediff emaiId and pwd in credentials.
    If you want to set up any other smtp service like as you said 'admin.labmateasia.net','test.com' etc. Then follow these steps:
    http://blog.powerbiz.net.au/exchange/how-to-set-up-an-internal-smtp-service-for-windows-server-2012-essentials/
    Or just configure 'SMTP Email' from IIS where your application is hosted as follows:
    https://technet.microsoft.com/en-us/library/cc772058(v=ws.10).aspx

  • #767286
    HI ,

    WHEN U HOST UR APPLICATION ON SERVER , CHANGE "ENABLE SSL =false;"
    Try this.


  • Sign In to post your comments