Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#ASP.NETWebForms
I cont able to send a mail using this code: Please help me with this code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net.Mime;
public partial class _Default : System.Web.UI.Page
MailMessage mail = new MailMessage();
private void clear()
TextBox2.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
protected void Button2_Click(object sender, EventArgs e)
{ {
SmtpClient mailserver = new SmtpClient();
mailserver.Credentials = new System.Net.NetworkCredential ("", "*******");
// mailserver.Port = 587; //gmail port: 587
mailserver.Host = ""; // ""; // //"" "";
mailserver.EnableSsl = false;
mail = new MailMessage();
String[] addr = TextBox2.Text.Split(',');
mail.From = new MailAddress("", "HI", System.Text.Encoding.UTF8);
Byte i;
for (i = 0; i < addr.Length; i++)
mail.Subject = TextBox4.Text;
mail.Body = TextBox5.Text;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.ReplyTo = new MailAddress(TextBox2.Text);
Label1.Visible = true;
Label1.Text = "Hi Your Massage Has been sent";
catch (Exception ex)
Label1.Visible = true;
Label1.Text = "mail not sent "+ ex.ToString();
protected void Button1_Click (object sender, EventArgs e)
This is the error i am getting:
mail not sent System.Net.Mail.SmtpFailedRecipientExcep… Mailbox name not allowed. The server response was: sorry, relaying denied from your location [] (#5.7.1) at System.Net.Mail.SmtpTransport.SendMail(M… sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMess… message) at _Default.Button2_Click(Object sender, EventArgs e) in
Posted 2-Aug-11 21:55pm
Edited 2-Aug-11 22:24pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

what I see from the error is that you use a different mail server than the network you are in. So that is way it is saying that relaying is denied.
and set: mailserver.DeliveryMethod = SmtpDeliveryMethod.Network;
Which mail client do you use on your development system?
manoharnch at 3-Aug-11 4:06am
digimanus at 3-Aug-11 4:50am
view for all detail settings
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

The link digimanus posted works like a charm thank you very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Guruprasad.K.Basavaraju 490
1 Shai Vashdi 339
2 Sergey Alexandrovich Kryukov 291
3 Peter Leow 135
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,185
1 OriginalGriff 5,335
2 Peter Leow 4,040
3 Maciej Los 3,540
4 Abhinav S 3,308

Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 24 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid