Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - Sending Emails via SMTP/System.Net.Mail
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Sending Emails via SMTP/System.Net.Mail

 Post Reply Post Reply
Author
IanSmithISA View Drop Down
Groupie
Groupie


Joined: 21 October 2010
Location: Worcester
Status: Offline
Points: 127
Post Options Post Options   Thanks (0) Thanks(0)   Quote IanSmithISA Quote  Post ReplyReply Direct Link To This Post Topic: Sending Emails via SMTP/System.Net.Mail
    Posted: 02 January 2011 at 12:25pm

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>

 

Back to Top
123Simples View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 July 2007
Location: United Kingdom
Status: Offline
Points: 1192
Post Options Post Options   Thanks (0) Thanks(0)   Quote 123Simples Quote  Post ReplyReply Direct Link To This Post Posted: 02 January 2011 at 7:02pm
Hi Ian
Are you just trying to create a contact form for the actual site, so people can fill it in, and you will get an email?
If so, contact me by PM and I'll see if I can give you the answer to do one for your site, as the code above is not going to work, and I'm not even sure how to understand it either
Back to Top
IanSmithISA View Drop Down
Groupie
Groupie


Joined: 21 October 2010
Location: Worcester
Status: Offline
Points: 127
Post Options Post Options   Thanks (0) Thanks(0)   Quote IanSmithISA Quote  Post ReplyReply Direct Link To This Post Posted: 03 January 2011 at 7:02am
Good morning
 
Thanks for the offer of help.
 
No I am not trying to create a  contact form, I just put it up as a form to show what I am doing.
The "real" page is at http://www.iansmithcse.co.uk/Login/Login.aspx?AppID=1 and "I am a new user" button
 
In practice it is part of a C# class that is used to send may different emails depending upon the action of the user within the site. Currently this site is being developed locally and I am checking that I can deploy it when ready.
 
The code works on my server and the servers that I used to use, so it is something pretty simple that is needs to be set to work with WebWiz's mail setup.
 
On my test sever I run both the mail server and IIS on the same server and I had a VPS with my previous host with the same arrangement. I plan to have a VPS here when I go live and get some traffic, but I am testing and starting of on a basic package.
 
Slightly off the orignal topic, I found that the VPS configurations offered by the previous host to be confusing. They offered cheap packages which never had the power to run a site, if you are gong to have a VPS you are almost cetain to want a database server and a mail server and RAM to usefully run these along with enough disc space to be able to run the updates.
 
Bye
 
Ian Smith
Why does anyone need more than an 80x25 character only VDU?
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9791
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 03 January 2011 at 12:55pm
You should read through the following page again as it would appear that you are not reading it correctly:-


A pickup directory would only work if there is a localhost mail server. We do not run mail servers on our web servers so the pickup directly method would not work.

What you need to do is first create a mailbox in your Control Panel, this will be the 'from' address for your website to send emails.

The mail server that you would be using to send emails is mail.websitelive.net so you would enter this as the mail server host which you would be connecting to across a network.

Our mail servers require authentication to relay emails to non local mailboxes. What you would need to do is set the 'from' address as the mailbox you have created in your Control Panel and for the authentication use the username and password for this same mailbox (the username is the full email address).
Back to Top
IanSmithISA View Drop Down
Groupie
Groupie


Joined: 21 October 2010
Location: Worcester
Status: Offline
Points: 127
Post Options Post Options   Thanks (0) Thanks(0)   Quote IanSmithISA Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2011 at 4:24pm
Good afternoon
 
Thank you for the reply.
 
What is driving me mad is that I think that I am doing this, but I keep getting the
 
"Mailbox unavailable. The server response was: Authentication is required for relay "
 
Finally worked it out.
 
            // Set credentials
            ncCreds.Domain = strServer;
            ncCreds.UserName = strUsername;
            ncCreds.Password = StrPassword;
            mcMailClient.Credentials = ncCreds;
 
Needs to be
 
            // Set credentials
            ncCreds.UserName = strUsername;
            ncCreds.Password = StrPassword;
            mcMailClient.Credentials = ncCreds;
 
Removed ncCreds.Domain entirely.
 
Bye
 
Ian


Edited by IanSmithISA - 06 January 2011 at 8:40am
Why does anyone need more than an 80x25 character only VDU?
Back to Top
lindajamison76 View Drop Down
Newbie
Newbie


Joined: 13 September 2011
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote lindajamison76 Quote  Post ReplyReply Direct Link To This Post Posted: 13 September 2011 at 8:35am

Well, great work! You have helped me to improve my knowledge about this field. Thank you so much for sharing.

__________
http://moviesonlinewatch.net/
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.