user7151301
user7151301

Reputation:

Email sending from 1and1 SMTP server

Trying to send email from 1and1 smtp server in ASP :

 MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress("[email protected]");
        Msg.To.Add("personalmail");
        SmtpClient smtp = new SmtpClient("auth.smtp.1and1.fr",465);
        smtp.Credentials = new NetworkCredential("[email protected]", "mypassword");
        smtp.EnableSsl = true;
        try
        {
            // smtp.Send(Msg);
            smtp.Send(Msg);
            return "ok";
        }
        catch (Exception e)
        {
            return e.ToString();
        }

The code goes in the catch with the error called :"net_io_connectionclosed" Do Someone know this problem ? Regards

Upvotes: 0

Views: 4009

Answers (2)

Nirtun
Nirtun

Reputation: 47

Hyrozen,

I had the same problem for a week, and i discover this code(i do not remember where...so the author thanks a lot). My page just have a textbox for the username and a textarea for the text and a button to send the email to contact me(that is why i put the sender the same for FROM and TO in the message):

try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(ConfigurationManager.AppSettings["Sender"]);
                message.To.Add(ConfigurationManager.AppSettings["Sender"]);
                message.Subject = "Comentario de " + TB_nomcomplet.Text;
                message.IsBodyHtml = false;
                message.Body = TB_texteemail.Text;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = ConfigurationManager.AppSettings["SmtpHost"];
                smtp.Credentials = new NetworkCredential("emailYours", "passwordYours");
                smtp.Send(message);

                LBL_messageEmail.Visible = true;
            }
            catch (Exception ex)
            {
                LBL_messageEmail.Text = "Error: " + ex.Message;
            }

And in the web.config:

<appSettings>
  <add key="SmtpHost" value="smtp.1and1.com" />
  <add key="Sender" value="emailYours" />
</appSettings>

Upvotes: 0

Vivien Chevallier
Vivien Chevallier

Reputation: 1522

Hyrozen,

You have to use Port 587.

Upvotes: 4

Related Questions