Email not working from Godaddy Server - asp.net

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);

Related

Unable to send in asp.net application

I want to send an e-mail, but it shows the following error:
try
{
string filename = Server.MapPath("~/App_Data/FeedBack.txt");
string mailbody = System.IO.File.ReadAllText(filename);
mailbody = mailbody.Replace("##Name##", txtName.Text);
mailbody = mailbody.Replace("##Email##",txtEmail.Text);
mailbody = mailbody.Replace("##contact##",txtContact.Text);
mailbody = mailbody.Replace("##Commnect##",txtSuggestion.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Responce from website";
myMessage.Body = mailbody;
myMessage.From = new MailAddress("amitverma0511#gmail.com","Amit Kumar");
myMessage.To.Add(new MailAddress("amitverma1150#gmail.com", "Amit Verma"));
SmtpClient mysmptclient = new SmtpClient("localhost");
mysmptclient.Host = "smtp.gmail.com";
mysmptclient.Port = 587;
mysmptclient.Credentials = new System.Net.NetworkCredential("amitverma0511#gmail.com", "Myemailpassword");
mysmptclient.Send(myMessage);
formatTable.Visible = false;
lblMail.Text = "Your Feedback has been sent successfully";
lblMail.ForeColor = Color.Green;
}
catch(Exception expt)
{
lblMail.Text = "unable to sent the feedback .Check your smpt server"+expt.Message;
lblMail.ForeColor = Color.Red;
}
My web.config file looks like this:
<system.net>
<mailSettings>
<smtp from="amitverma0511#gmail.com">
<network host="smtp.gmail.com" port='587' password="myemailpass" userName="amitverma0511#gmail.com"/>
</smtp>
</mailSettings>
</system.net>
As far as I know, you are overwriting your web.config settings by using localhost (your IIS) as a SMTP Server.
If you have not configured your IIS to serve as a SMTP server this naturally will not work.
But, if you want to use localhost and not the google servers just use this 3 lines:
SmtpClient MySmtpClient = new SmtpClient();
MySmtpClient.UseDefaultCredentials = true;
MySmtpClient.Send(mailMessage);
You should remove the string localhost from SmtpClient mysmptclient = new SmtpClient("localhost"); and it should work, if all your other settings are correct.
Further information can be found here.

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

how to send a confirmation email in asp.net, cannot get IIS pickup directory error

I want to send a confirmation email to user in registration page. The following code is the related part:
try
{
SmtpClient sc = new SmtpClient();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
string Ema = u.UserMail.ToString();
MailAddress gonderen = new MailAddress("admin#gmail.com", "Hello");
sc.Host = "smtp.gmail.com";
sc.Port = 587;
mail.To.Add(Ema);
mail.Subject = "Confirmation Message";
mail.From = gonderen;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-9");
mail.Body = "<html><body>";
sc.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
sc.Send(mail);
MESSAGE(true, "Sending mail is successful");
}
catch (Exception)
{
MESSAGE(true, "Sending mail is unsuccessful!");
}
But it does not send an email to related user. I have looked at forums and I added to web.config the following part:
<system.net>
<mailSettings>
<smtp from="myaddress#gmail.com ">
<network host="smtp.gmail.com" defaultCredentials="false"
port="587" userName ="myaddress#gmail.com" password="password" />
</smtp>
</mailSettings>
</system.net>
But anything didn't change. Then i have debugged and it enters into the try statement and when it comes to sc.Send(mail);, it drops to catch. Where is my mistake?
Additionally, during debug i realized that it shows this error: cannot get IIS pickup directory. I have controlled whether I have a smtp service or not from services but i couldn' t see this service. Is this error related to that service?
Thanks in advance.
Why not use GMAIL as the SMTP server, since you are defining a GMAIL account, by defining the host as "smtp.gmail.com", and port at 587?
Specific details here: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
Thanks for your helps.
I have solved this problem. I have changed my code as the following one:
try
{
SmtpClient sc = new SmtpClient();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
string Ema = u.UserMail.ToString();
MailAddress gonderen = new MailAddress("admin#gmail.com", "Hello");
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.EnableSsl = true;
mail.To.Add(Ema);
mail.Subject = "Confirmation Message";
mail.From = gonderen;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-9");
mail.Body = "<html><body>";
mail.Body += "</body></html>";
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(mail);
MESAJ(true, "Sending mail is successful");
}
catch (Exception)
{
MESAJ(true, "Sending mail is unsuccessful!");
}
and then i have set my web.config like the following :
<mailSettings>
<smtp deliveryMethod="Network"
from="admin#gmail.com">
<network defaultCredentials="false" host="smtp.gmail.com" port="587"
userName="admin#gmail.com" password="password" />
</smtp>
</mailSettings>
that works.. :)

Email alert when page is open

Is there any way in asp.net that when my page is open on web then an email alert with username should be generate so that i have information that which one is accessing my page
I changed the code like bellow
Public Sub SendMail(ByVal id As String)
Dim message = New MailMessage()
message.IsBodyHtml = True
message.From = New MailAddress("adeel.aslam0#gmail.com")
message.[To].Add(New MailAddress("malik.adeel#shakarganj.com"))
message.Subject = "user access page"
message.Body = "Your Message"
' add id here
Dim client = New SmtpClient("smtp.gmail.com")
client.Send(message)
End Sub
and in web.config like this
<system.net>
<mailSettings>
<smtp from="adeel.aslam0#gmail.com">
<network host="smtp.gmail.com" defaultCredentials="false"
port="587" userName ="adeel.aslam0#gmail.com" password="pass" />
</smtp>
</mailSettings>
</system.net>
You might do something similar..
Modify your web.config file to send emails
e.g. This use gmail settings
<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>
And in your page_load
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
var user = HttpContext.Current.User;
if (user != null && user.Identity.IsAuthenticated)
{
var id = Membership.GetUser().ProviderUserKey;
SendMail(id.ToString());
}
}
}
public void SendMail(string id)
{
var message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress("yourmail");
message.To.Add(new MailAddress("tomail"));
message.Subject= "user access page";
message.Body = "Your Message";// add id here
var client = new SmtpClient();
client.Send(message);
}
if you using vb try something like this.
This way, you will not need to change your web.config
Dim mailobject As New System.Net.Mail.MailMessage()
Dim myCred As New System.Net.NetworkCredential("yourmail#gmail.com", "password")
mailobject.To.Add("tomail")
mailobject.Subject = "User Access The Page"
mailobject.From = New System.Net.Mail.MailAddress("frommail")
mailobject.IsBodyHtml = True
mailobject.Body = "Your Message"
Dim SmtpMail As New System.Net.Mail.SmtpClient("smtp.gmail.com")
SmtpMail.UseDefaultCredentials = False
SmtpMail.EnableSsl = True
SmtpMail.Credentials = myCred
SmtpMail.Port = 587
SmtpMail.Send(mailobject)
Fair question. But you really do not want to do this unless you have a very limited amount of visitors. See the answer above on how to do it.
Better write everything into a table and send yourself a digest at certain interval per hour/day. This way you can also do some reporting afterwards using that table.

Cannot send email in ASP.NET through Godaddy servers

I have an ASP.NET application hosted on Godaddy that I want to send email from. When it runs, I get: Mailbox name not allowed. The server response was: sorry, relaying denied from your location. The important parts of the code and Web.config are below:
msg = new MailMessage("accounts#greektools.net", email);
msg.Subject = "GreekTools Registration";
msg.Body =
"You have been invited by your organization to register for the GreekTools recruitment application.<br/><br/>" +
url + "<br/><br/>" +
"Sincerely,<br/>" +
"The GreekTools Team";
msg.IsBodyHtml = true;
client = new SmtpClient();
client.Host = "relay-hosting.secureserver.net";
client.Send(msg);
<system.net>
<mailSettings>
<smtp from="accounts#greektools.net">
<network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" />
</smtp>
</mailSettings>
1- If your site is hosted on godaddy you may use "relay-hosting.secureserver.net" without credentials.
2- If your site is hosted outside of godaddy you may use "smtpout.secureserver.net" with you email account credentials.
PS: Please change port 3535 if you have problems with 25
Hosted On GoDaddy
<system.net>
<mailSettings>
<smtp from="abc#xyz.net">
<network host="relay-hosting.secureserver.net"/>
</smtp>
</mailSettings>
</system.net>
External
<system.net>
<mailSettings>
<smtp from="abc#xyz.net">
<network host="smtpout.secureserver.net"
userName="abc#xyz.net" password="your_password_here"
port="25" />
</smtp>
</mailSettings>
</system.net>
Here's my email class:
public class Email
{
public enum MailAddressType
{
From = 1,
Bcc
}
private static MailAddress _from = null;
public static void SendEmail(string to, string subject, string body)
{
SendEmail(to, subject, body, From, string.Empty);
}
public static void SendEmail(string to, string subject, string body, string from)
{
SendEmail(to, subject, body, from, MailAddressType.From);
}
public static void SendEmail(string to, string subject, string body, string addresses, MailAddressType addressType)
{
MailAddress from = From;
string bcc = string.Empty;
if (MailAddressType.From == addressType)
{
from = new MailAddress(addresses);
}
else
{
bcc = addresses;
}
SendEmail(to, subject, body, from, bcc);
}
private static void SendEmail(string to, string subject, string body, MailAddress from, string bcc)
{
MailMessage message = new MailMessage();
message.From = From;
message.To.Add(to);
if (!string.IsNullOrEmpty(bcc))
{
message.Bcc.Add(bcc);
}
message.ReplyTo = from;
message.Subject = subject;
message.Body = HttpContext.Current.Server.HtmlEncode(body);
SmtpClient smtp = new SmtpClient();
smtp.Send(message);
}
public static MailAddress From
{
get
{
if (null == _from)
{
SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
string address = section.From;
string displayName = ConfigurationManager.AppSettings["fromEmailDisplayName"];
_from = new MailAddress(address, displayName);
}
return _from;
}
}
}
And here are the related web.config settings:
<appSettings>
<add key="fromEmailDisplayName" value="Firstname Lastname"/>
</appSettings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="myname#mydomain.com">
<network host="relay-hosting.secureserver.net" />
</smtp>
</mailSettings>
</system.net>
For me, the key was "message.From = From" and "message.ReplyTo = from". GoDaddy seems to want the message to come from an address in your domain. So for contact pages, use your default email address as the From and set the sender as the ReplyTo. Email goes through fine after that.
This is likely a reply from the SMTP server because the machine attempting to send email has not been whitelisted (or is blacklisted for SPAM). Is relay-hosting.secureserver.net a GoDaddy server, or is it on a different network? You might want to find a GoDaddy server that enables email to be relayed. I would imagine a lot of shared hosting providers have restrictions today.
I would find out what type of SMTP server you are using and what anti-spam measures are in place. The administrator may be able to add the GoDaddy server to the whitelist of allowed hosts. You need to be very careful and make sure that you application cannot be used as a proxy for a spammer. Make sure to validate all input to ensure it it safe.
Check your hostname. Are you sure your account isn't configured to use mail.greektools.net ?That's the default format for GoDaddy webhosting..
set
defaultCredentials="false"
in your network element
<network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" defaultCredentials="false" />
What email or relay server should I use in my ASP.NET 3.5 code?
You do not need to provide a user name
and password for this relay server.
Just for a test. Remove the username and password values from the web.config.
Then, in your code set
//call this line, before you call .Send
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(msg)
I just asked GoDaddy, how to set up a SMTP form mailer, and they told me that I'd need to use a Relay Server, with no username, no password, and no port. The server name to use was, the same name that you used.
var message = new MailMessage();
message.To.Add(new MailAddress("email-address"));
message.From = new MailAddress("email-address");
message.Subject = "subject";
message.Body = string.Format("message-body");
message.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.Host = "relay-hosting.secureserver.net";
smtp.EnableSsl = false;
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
await smtp.SendMailAsync(message);
}
For those who want to know what should be C# code in addition to the accepted answer, below code worked for me. Please note that "from" address is already mentioned in web.config in the accepted answer, so no need to mention it in C# code.
public static void SendMail(string emailid, string subject, string body)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(new MailAddress(emailid));
msg.Subject = subject;
msg.IsBodyHtml = true;
msg.Body = body;
client.Send(msg);
}
Try below code:
smtp.Host = "relay-hosting.secureserver.net";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("test#yourwebsitedomain.com", "*******");
It worked for me.
The code working for me for Go Daddy email send from c# code
var smtp = new SmtpClient
{
Host = "smtpout.secureserver.net",
Port = 25,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("domain.xyz.com", "password...")
};
using (var message = new MailMessage("domain.xyz.com", "domain.xyz.com")
{
IsBodyHtml = false,
Subject = modal.Subject,
Body = modal.Body
})
{
smtp.Send(message);
}

Resources