550-5.7.1[122.163.196.231] the ip you’re using to send mail is not authorized"
i have configure smtp server put 127.0.0.1 ip in relay and also put 127.0.0.1 ip in connection.
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Web;
- using System.Web.Mail;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace EMailSample
- {
- public partial class SendMail : System.Web.UI.Page
- {
- protected void Page_Load(object sender, System.EventArgs e)
- {
- if (!IsPostBack)
- {
- }
- lblMessage.Text = "";
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- }
- #endregion
- protected void btnsend_Click(object sender, EventArgs e)
- {
- try
- {
- /* Create a new blank MailMessage */
- MailMessage mailMessage = new MailMessage();
- mailMessage.From = txtSender.Text;
- mailMessage.To = txtReceiver.Text;
- mailMessage.Cc = txtCc.Text;
- mailMessage.Bcc = txtBcc.Text;
- mailMessage.Subject = txtSubject.Text;
- mailMessage.Body = txtBody.Text;
- /* Set the properties of the MailMessage to the
- values on the form */
- if (rblMailFormat.SelectedItem.Text == "Text")
- mailMessage.BodyFormat = MailFormat.Text;
- else
- mailMessage.BodyFormat = MailFormat.Html;
- /* We use the following variables to keep track of
- attachments and after we can delete them */
- string attach1 = null;
- string attach2 = null;
- string attach3 = null;
- /*strFileName has a attachment file name for
- attachment process. */
- string strFileName = null;
- /* Bigining of Attachment1 process &
- Check the first open file dialog for a attachment */
- if (inpAttachment1.PostedFile != null)
- {
- /* Get a reference to PostedFile object */
- HttpPostedFile attFile = inpAttachment1.PostedFile;
- /* Get size of the file */
- int attachFileLength = attFile.ContentLength;
- /* Make sure the size of the file is > 0 */
- if (attachFileLength > 0)
- {
- /* Get the file name */
- strFileName = Path.GetFileName(inpAttachment1.PostedFile.FileName);
- /* Save the file on the server */
- string path = Server.MapPath(strFileName);
- inpAttachment1.PostedFile.SaveAs(path);
- /* Create the email attachment with the uploaded file */
- MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
- /* Attach the newly created email attachment */
- mailMessage.Attachments.Add(attach);
- /* Store the attach filename so we can delete it later */
- attach1 = strFileName;
- }
- }
- /* Attachment-2 Repeat previous step */
- if (inpAttachment2.PostedFile != null)
- {
- HttpPostedFile attFile = inpAttachment2.PostedFile;
- int attachFileLength = attFile.ContentLength;
- if (attachFileLength > 0)
- {
- strFileName = Path.GetFileName(inpAttachment2.PostedFile.FileName);
- inpAttachment2.PostedFile.SaveAs(Server.MapPath(strFileName));
- MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
- mailMessage.Attachments.Add(attach);
- attach2 = strFileName;
- }
- }
- /* Attachment-3 Repeat previous steps */
- if (inpAttachment3.PostedFile != null)
- {
- HttpPostedFile attFile = inpAttachment3.PostedFile;
- int attachFileLength = attFile.ContentLength;
- if (attachFileLength > 0)
- {
- strFileName = Path.GetFileName(inpAttachment3.PostedFile.FileName);
- inpAttachment3.PostedFile.SaveAs(Server.MapPath(strFileName));
- MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
- mailMessage.Attachments.Add(attach);
- attach3 = strFileName;
- }
- }
- /* Set the SMTP server and send the email with attachment */
- // SmtpMail.SmtpServer = "127.0.0.1";
- SmtpMail.SmtpServer.Insert(0, "127.0.0.1");
- //SmtpMail.SmtpServer.Insert(0,"192.168.1.7");
- SmtpMail.Send(mailMessage);
- /* Delete the attachements if any */
- if (attach1 != null)
- File.Delete(Server.MapPath(attach1));
- if (attach2 != null)
- File.Delete(Server.MapPath(attach2));
- if (attach3 != null)
- File.Delete(Server.MapPath(attach3));
- /* clear the controls */
- txtSender.Text = "";
- txtReceiver.Text = "";
- txtCc.Text = "";
- txtBcc.Text = "";
- txtSubject.Text = "";
- txtBody.Text = "";
- /* Dispaly a confirmation message to the user. */
- lblMessage.Visible = true;
- lblMessage.ForeColor = Color.Black;
- lblMessage.Text = "Message Sent.";
- }
- catch (Exception ex)
- {
- /* Print a message informing the
- user about the exception that was risen */
- lblMessage.Visible = true;
- lblMessage.ForeColor = Color.Red;
- lblMessage.Text = ex.ToString();
- }
- }
- }
- }