Last post Apr 12, 2020 08:28 AM by Kulrom
Apr 11, 2020 10:43 PM|wotermelan|LINK
Hi, i'm student who is trying to develop a digital portfolio for myself with a contact page, however, I have a problem with receiving the email that is sent to my outlook account. When i click the send button it will load the page and not show any error
meaning that the email technically sent but when I check for any new mails there are none. I'm also wondering if this is the most secure way to do this after all this will be published eventually.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h1 class="MainTitle">Contact Me</h1>
<label for="fname">Full Name</label>
<asp:textbox type="text" id="fname" class="fname" runat="server" name="firstname"
placeholder="Your name here"/>
<asp:textbox type="text" id="from" class="from" runat="server" name="from"
<asp:textbox id="body" name="body" CssClass="body" runat="server" placeholder="Write
something..." style="height:200px" TextMode="MultiLine"></asp:textbox>
<asp:button text="Send" Class="Sendbtn" value="Submit" runat="server"
protected void Page_Load(object sender, EventArgs e)
string to = "myEmail@outlook.com";
protected void submit_Click(object sender, EventArgs e)
MailMessage msg = new MailMessage(to, from.Text, fname.Text, body.Text);
//CONFIGURE SMTP OBJECT
SmtpClient client = new SmtpClient("smtp-mail.outlook.com", 587);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(to, "myPassword");
Apr 12, 2020 08:07 AM|PatriceSc|LINK
The message is perhaps not sent at all. In the catch block you are doing at all with the message and so you are just hiding any exception that could occur. I would remove the try/catch block for now to see what happens.
Once this particular problem is solved look at best practices for handling exceptions. In particular if you just want to log exceptions it can be done at a higher level rather than locally in each method.
Apr 12, 2020 08:28 AM|Kulrom|LINK
try setting the smtp to mail.live.com
In addition please notice that sometimes you need to approve the sending emails from within the email settings (outlook)