Subscription Page in asp.net - asp.net

I have a registration page I am sending an email from asp.net ,one mail to the registered user and other mail to the admin that too with different body...Ho can I achieve this? Also, User should give a confirmation link saying that you have subscribed and when the user clicks on the mail given link , a mail should fire to the admin saying that This User has been Registered.

http://www.webcodeexpert.com/2013/08/create-registration-form-and-send.html
You can use this link to achive the activation for user. But for sending mail to the admin, Use simple send email method.

Try this way, Send the from address and body details by yourself .
public void SendMail(string FromEmail, string Subject, string Body)
{
string ToEmail="YourAdmin#Gmail.com";
System.Net.Mail.MailMessage eMail = new System.Net.Mail.MailMessage();
eMail.From = new System.Net.Mail.MailAddress(FromEmail);
eMail.To.Add(ToEmail);
eMail.Subject = Subject;
eMail.IsBodyHtml = true;
eMail.Body = Body;
System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient();
SMTP.Send(eMail);
eMail.Dispose();
}
Web.Config:
<system.net>
<mailSettings>
<smtp>
<network host="your stmp server" port="25" userName="your from email" password="your password"/>
</smtp>
</mailSettings>
</system.net>
Should be you have mail hosting server .
and if you want to send mail without page postback , See my little bit blog

These lines of code is used to send mail in aspx.cs page,make a try.if yo are using asp.net with c#
in aspx
<asp:CheckBox ID="CheckBoxMark1" runat="server" />
CheckBox Ckbox = (CheckBox)row.FindControl("CheckBoxMark1");
if (Ckbox.Checked == true)
{
sendMail(toemail);
//other code
}
public void sendMail(String toemail)
{
MailMessage mail = new MailMessage();
mail.To.Add(toemail);
mail.From = new MailAddress("sender#gmail.com");
mail.Subject = "Subject";
mail.Body = " Your Contents in the mail";
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("sender#gmail.com", "Password");
smtp.EnableSsl = true;
smtp.Send(mail);
}

Related

Email not sending using SMTP in ASP.net

I am try to send email through SMTP in ASP.net but email not sending and not giving any error. My code:
//create the mail message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//set the FROM address
mail.From = new MailAddress("aaa#abc.com");
//set the RECIPIENTS
mail.To.Add("bbb#abc.com");
//enter a SUBJECT
mail.Subject = "Set the subject of the mail here.";
//Enter the message BODY
mail.Body = "Enter text for the e-mail here.";
//set the mail server (default should be smtp.1and1.com)
SmtpClient smtp = new SmtpClient("smtp.1and1.com");
//Enter your full e-mail address and password
smtp.Credentials = new NetworkCredential("example#abc.com", "xxxxxxx");
//send the message
smtp.Send(mail);
And my code in web.config is
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Mail\" />
</smtp>
</mailSettings>
<defaultProxy enabled="true" />
</system.net>
Use breakpoint to display each parameter's value. Even if there is no error in the codes, parameter's value may be null or wrong. Before breakpoint, use try-catch as it below;
try
{
// Your codes
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
Check First you TLS Version.
Open your Site in IE(Internet Explorer) browser and go to page properties.
If your TLS 1.2 then Add below code before client.Send(Object);
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
like as per bellow
System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.Send(oMail);
client.Dispose();
client = null;

Email not working from Godaddy Server

First of all, I hope to be at the right place, I apologize in advance if this is not the case, please re-orient myself.
So here I have a worry, I have a website www.artipik.com with two forms, online quote and contact form.
My website is hosted by godaddy and servers were updated summers there for 15 days and my form are no longer work, which put me in a very problematic position. I'm a graphic designer not a coder, hence my difficulty changed the code.
I had the godaddy technical service and he gave it to me I think part of the solution. I found the place to change the code, but I can not seem to fit, I'm testing, I no further error messages but I do not receive any email I send.
My current ASP code is as follows:
<%
'-----version CDONTS-----
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.BodyFormat = 1 '0:html/1:plain text
Mail.MailFormat = 1 '0:MIME/1:plain text
Mail.From = envoyeur
Mail.To = receveur
if copie<>vbnullstring then Mail.Bcc = copie
if sujet=vbnullstring then sujet="Formulaire de contact Artipik.com"
Mail.Subject = sujet
Mail.Body = message
Mail.Send
set Mail=Nothing
'response.cookies("email")=envoyeur
%>
and the new code that I have to adapt is the following (Using CDOSYS to Send Email from Your Windows Hosting Account):
// language -- C#
// import namespace
using System.Web.Mail;
private void SendEmail()
{
const string SERVER = "relay-hosting.secureserver.net";
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.From = "emailaddress#domainname";
oMail.To = "emailaddress#domainname";
oMail.Subject = "Test email subject";
oMail.BodyFormat = MailFormat.Html; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = "Sent at: " + DateTime.Now;
SmtpMail.SmtpServer = SERVER;
SmtpMail.Send(oMail);
oMail = null; // free up resources
}
Thank you for your help.
Julian
System.Web.Mail.MailMessage is obsolete. You should use System.Net.Mail.MailMessage instead. It works almost exactly the same (warning! untested):
private void SendEmail()
{
using (var message = new MailMessage())
{
message.From = new MailAddress("emailaddress#domainname");
var toAddress = new MailAddress("emailaddress#domainname");
message.To.Add(toAddress);
message.Subject = "Test email subject";
message.Body = "Sent at: " + DateTime.Now;
message.Priority = MailPriority.High;
message.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Send(message);
}
}
Add this to your web.config:
<configuration>
<system.net>
<mailSettings>
<smtp from="emailaddress#domainname">
<network host="your-smtp-host-address" />
</smtp>
</mailSettings>
</system.net>
</configuration>
Recently I've had the same problem, could solve it throug the next way:
in web.config:
<system.net>
<mailSettings>
<smtp from="contacto#mydomain.com">
<network host="relay-hosting.secureserver.net" password="MyPass" port="25" enableSsl="false" defaultCredentials="false" userName="contacto#mydomain.com"/>
</smtp>
</mailSettings>
</system.net>
in codebehind:
MailMessage m = new MailMessage();
m.IsBodyHtml = true;
m.Body = "My Message";
m.To.Add("jhon.doe#yahoo.com");
m.Subject = "Go Daddy Emails Go Live!";
SmtpClient smtp = new SmtpClient();
smtp.Send(m);

Send email using asp.net

I want to send email using asp.net, I have configured my SMTP service and added 127.0.0.1 as relay. I used to my home the application was success but I installed on the office it cannot send email why?
here is the C# code
MailMessage objemail = new MailMessage();
objemail.To.Add(new MailAddress("apthodisiac#gmail.com"));
objemail.From = new MailAddress(Request.Form["inputEmail"].ToString());
objemail.Subject = Request.Form["inputSubject"].ToString();
objemail.Body = "Dari: " + Request.Form["inputName"].ToString() + "\n\n" +
"Phone: " + Request.Form["inputPhone"].ToString() + "\n\n" +
Request.Form["inputMsg"].ToString();
objemail.IsBodyHtml = true;
objemail.Priority = MailPriority.Normal;
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.Send(objemail);
here is the web.config configuration
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="127.0.0.1" port="25" userName="yyyy" password="xxxxx" />
</smtp>
</mailSettings>
</system.net>
My office use proxy, is that the problem I cannot send email? please advice
May be port number is wrong try with port number "587" something as shown below:
private void SendEmail(string from, string to, string subject, string body)
{
MailMessage mail = new MailMessage(new MailAddress(from), new MailAddress(to));
mail.Subject = subject;
mail.Body = body;
SmtpClient smtpMail = new SmtpClient("smtp.gmail.com");
smtpMail.Port = 587;
smtpMail.EnableSsl = true;
smtpMail.Credentials = new NetworkCredential("xxx#gmail.com", "xxx");
// and then send the mail
smtpMail.Send(mail);
}
you can try this:
objSmtpClient.EnableSsl = true

SMTP server not sending mail

I got Message that mail sent. But in Inbox there is no new email i have found that email in
server inetpub-> mailroot-> Queue
Please tell me the solution for this
Edited
public string btnSendmail()
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("myemail#itaxsmart.com","");
smtpClient.Host = "localhost";
smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add("mailsendtol#itaxsmart.com");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = "Hello World" ;
smtpClient.Send(message);
return "Email successfully sent.";
}
catch (Exception ex)
{ return "Send Email Failed." + ex.Message;
}
Is your SMTP started? If not, start it. If it is already started, try restarting it.
Also turn on logging and see if that helps.
The moment asp.net manages to sent the message to the smtp server, you will get a success message. This only means that the message has reached your smtp server.
asp.net cannot control what your smtp server does with it.
Try using a public smtp server like gmail, if your local smtp server is giving trouble.
Add This code to your web.config
<system.net>
<mailSettings>
<smtp>
<network host="relay-hosting.secureserver.net"/>
</smtp>
</mailSettings>
</system.net>
and Remove This
smtpClient.Host = "localhost";
smtpClient.Port = 25;
Thanks,
Subhankar

How to use gmail SMTP in ASP.NET form

I am a ASP novice and am troubleshooting a form for work. None of us here are ASP experts as we use PHP. But I am on the bottom of PHP experience as well, mostly working with HTML/CSS alone. My current forms credentials look like:
rotected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit Sub
Dim SendResultsTo As String = "email to"
Dim smtpMailServer As String = "email server"
Dim smtpUsername As String = "email username"
Dim smtpPassword As String = "password"
Dim MailSubject As String = "Form Results"
How would I go about making this form send to a Gmail address? I know I must include the port (587) somewhere, but cannot figure out where, as this form doesn't match the syntax of any other forms I have seen. Any help would be greatly appreciated!
You can add this in your web.config file
<system.net>
<mailSettings>
<smtp from="yourMailId#gmail.com ">
<network host="smtp.gmail.com" defaultCredentials="false"
port="587" userName ="yourmail#gmail.com" password="yourpassword" />
</smtp>
</mailSettings>
</system.net>
protected void SendMail()
{
MailMessage msg = new MailMessage();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
try
{
msg.Subject = "Add Subject";
msg.Body = "Add Email Body Part";
msg.From = new MailAddress("Valid Email Address");
msg.To.Add("Valid Email Address");
msg.IsBodyHtml = true;
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("Valid Email Address", "Password");
client.Port = int.Parse("587");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(msg);
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
Create a System.Net.Mail.SmtpClient object, set the SMTP server info you are using.
Then create a System.Smtl.MailMessage with the message data and send it:
using (System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient()) {
using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("from*where.com", "to#where.com") {
IsBodyHtml = true,
Subject = "Subject text",
Body = messageBody,
}) {
mail.Send(message);
} // using
You can configure your SmtpClient in the constructor, we use web.comfig, so I don't have that code.
Google now blocks sign-ins from an app (even over SSL) to send an email. You have two options:
Enable less-secure apps for the account you are using; OR
Generate an app-password from Google (recommended)
For option 2, you will have to enable 2-factor authentication before you can generate an app pasword.
Here are the steps I took to get this working on my ASP.NET web app
How to configure an ASP.NET web app with Gmail SMTP
Try this.
Dim client As New Net.Mail.SmtpClient
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential("sender#gmail.com", "password")
client.Host = "smtp.gmail.com"
client.Port = 587
client.EnableSsl = True
client.Send("sender#gmail.com","reciever#gmail.com","subject","body")
If you're using 2-step verification, don't forget to generate an application specific password and use that, not the password you use to log on to Gmail.
(Sorry I can't add this as a comment. Not enough rep at the time of posting this.)
There's no shortage of tutorials on how to send an email from within .NET.
Essentially you want a System.Net.Mail.SmtpClient object to interact with the SMTP server, a System.Net.Mail.MailMessage object to hold the message data, and configuration data in your config file to direct the client on how/where to send the message.

Resources