cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution
Highlighted
New

Asp.net site does not send email

Hello everyone. I am new in goddady,  I have a asp.net mvc site here, but email sending not working. In server code I write the following 

var emailmessage = new System.Web.Mail.MailMessage()
            {
                Subject = subject,
                Body = body,
                From = from,
                To = to,
                BodyFormat = MailFormat.Html,
                Priority = MailPriority.High
            };
           

            SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
            SmtpMail.Send(emailmessage);

In web config I added the code 

<system.net>
  <mailSettings>
   <smtp from="admin@flex.am">
    <network host="relay-hosting.secureserver.net"/>
   </smtp>
  </mailSettings>
 </system.net>

What can I do else?

Thanks!

5 REPLIES 5
Helper V

Re: Asp.net site does not send email

One thing you can do is to stop ignoring exceptions. Look at the sample in SmtpMail Class (System.Web.Mail). It shows extensive use of try/catch. In your situation, you might not be getting an exception but you should catch exceptions anyway.

 

Developers don't want to be bothered with exceptions and we often don't write enough code for exceptions. Beginners often don't think to check for exceptions before asking for help. The sample code in the MSDN shows how complicated cose such as that can be but code like that can make problems much easier to diagnose.

 

Also note that there is a separate forum in the GoDaddy forums for developers. Questions such as this about code should be there, but I am not a moderator; I am just another customer. However if I want to only answer developer questions then I would never see a developer question posted in a non-developer forum.

New
Solution

Re: Asp.net site does not send email

Ok. Anyway I found the solution. I had to use this class

SmtpClient smtp = new SmtpClient();

 

Email not sending(ASP.NET)

This code work fine from local machine and send email but in godaddy production environment

not sending email.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;

/// <summary>
/// Summary description for MailSer
/// </summary>
public class MailSer
{
    public MailSer()
    {

    }
    String MailFrom;
    String MailTo;
    String Subject;
    String Body;
    public String sendMail(String MailTo, String Subject, String Body)
    {
        String str = "0";
        try
        {
            using (SmtpClient smtpClient = new SmtpClient())
            {
                smtpClient.Host = "outlook.office365.com";
                smtpClient.EnableSsl = true;
                smtpClient.Port = 587;
                MailMessage message = new MailMessage();
                MailAddress fromAddress = new MailAddress("");
                MailAddress toAddress = new MailAddress(MailTo);
                smtpClient.Credentials = new System.Net.NetworkCredential("", "");
                message.From = fromAddress;
                message.To.Add(toAddress);
                message.IsBodyHtml = true;
                message.Subject = Subject;
                message.Body = Body;
                smtpClient.Send(message);
                str = "1";

            }
        }
        catch
        {
            str = "Connect TO Mail Failed";
        }
        return str;
    }
}

Re: Email not sending(ASP.NET)

Where is the proper solution for sending email from a hosted plesk account?

New
Solution

Re: Asp.net site does not send email

Well, i have spent many days trying to figure out what caused this issue? Why it is working locally and it doesn't work after published!!

 

1) Firstly

You need to follow the code written above by Artush

 

2) if you are working locally:

You need to set SMTP server name as your server name "which is the logic and normal way" that's why it is working locally lol

 

3) To make it works on godaddy

YOU NEED TO CHANGE SMTP SERVER NAME TO MATCH GODADDY SMTP SERVER "relay-hosting.secureserver.net"

 

Please notice that if you try to run your application using godaddy smtp server name "locally" it wont work but it will after published

 

Thanks!!

Salih