Good morning
I am going mad trying to send an email from my website, it worked on my test server but that is probably setup differently.
I did find http://www.webwiz.net/kb/webhosting/sending_web_form_mail.asp but I guess I am misunderstanding what it is telling me.
I have even put a page up at
http://www.iansmithcse.co.uk/MailTst1.aspx which is hosted here which allows me to type whatever I want, as this is a quicker test method, as well as select delivery method.
If I use IIS pickup I alway get "Cannot get IIS pickup directory.",
if I use network and putting values into From and To allows me to use an email address that is hosted to send to an email address hosted here, but I can not send to an non webwiz hosted address, I get the "Mailbox unavailable. The server response was: Authentication is required for relay " error.
If I put an non webwiz hosted address in the from box and a webwiz hosted address in the To box, the mail is sent as well.
Any suggestions would be greatfully received.
Thanks and bye
Ian Smith
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
namespace TheVillage
{
public partial class MailTst1 : System.Web.UI.Page
{
protected void PickupIIS_Click(object sender, EventArgs e)
{
SendMail(SmtpDeliveryMethod.PickupDirectoryFromIis);
}
protected void Network_Click(object sender, EventArgs e)
{
SendMail(SmtpDeliveryMethod.Network);
}
protected void SendMail(SmtpDeliveryMethod i32Method)
{
MailMessage mailMsg; SmtpClient mcMailClient;
String strFrom, strTo, strSubject, strBody;
String strServer, strUsername, StrPassword;
System.Net.NetworkCredential ncCreds = new System.Net.NetworkCredential();
strServer = this.txtMailServer.Text.ToString();
strUsername = this.txtUserName.Text.ToString();
StrPassword = this.txtPassword.Text.ToString();
strFrom = this.txtFrom.Text.ToString();
strTo = this.txtTo.Text.ToString();
strSubject = "Test subject";
strBody = "Test body";
// Create a mail object
mailMsg = new MailMessage(strFrom, strTo, strSubject, strBody);
// Create a mail client
mcMailClient = new SmtpClient();
mcMailClient.UseDefaultCredentials = false;
mcMailClient.DeliveryMethod = i32Method;
mcMailClient.Host = strServer;
// Set credentials
ncCreds.Domain = strServer;
ncCreds.UserName = strUsername;
ncCreds.Password = StrPassword;
mcMailClient.Credentials = ncCreds;
// Send Issuer email
mcMailClient.Send(mailMsg);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MailTst1.aspx.cs" Inherits="TheVillage.MailTst1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Mail server <asp:TextBox runat="server" ID="txtMailServer" Text="mail.WebSiteLive.net"></asp:TextBox><br />
Email From <asp:TextBox runat="server" ID="txtFrom" Text="
IanS@IanSmithCSE.co.uk"></asp:TextBox><br />
Email To<asp:TextBox runat="server" ID="txtTo" Text="
IanS@IanSmithCSE.co.uk"></asp:TextBox><br />
Webwiz Mail Name<asp:TextBox runat="server" ID="txtUserName" Text="IanS"></asp:TextBox><br />
webwiz Mail Password <asp:TextBox runat="server" ID="txtPassword" Text=""></asp:TextBox><br />
<asp:LinkButton ID="lbLogin" runat="server" Width="150px" OnClick="PickupIIS_Click" TabIndex="10">Send Mail -
PickupIIS</asp:LinkButton><br /><br />
<asp:LinkButton ID="LinkButton1" runat="server" Width="150px" OnClick="Network_Click" TabIndex="10">Send Mail -
Network</asp:LinkButton><br />
</div>
</form>
</body>
</html>