We have set up a web site for a client who uses Google Apps for their emails.
In the web site's contact us section, we have a form to enable a visitor send them a message. In short, the below code is used but it always times out during the 'send' phaze.
Dim mysmtp = New System.Net.Mail.SmtpClient
mysmtp.Host = "smtp.gmail.com"
mysmtp.Port = 465
mysmtp.EnableSsl = True
mysmtp.Timeout = 15000 ' it times out a lot later after removing this..
Dim msg As System.Net.Mail.MailMessage
msg = New System.Net.Mail.MailMessage(from:="info#xxx.org", subject:="text", body:="still testing ...", [to]:="xx#gmail.com")
Dim smtpAuthentication As New System.Net.NetworkCredential()
smtpAuthentication.Password = "mypwd"
smtpAuthentication.UserName = "info#xxx.org"
mysmtp.Credentials = smtpAuthentication
mysmtp.Send(msg)
I have tried it with firewall turned off, and anti-virus software disabled. I am using windows 7.
None of the solutions in other questions/forms worked. The problem might not be the code but I am lost.
Any help would be appreciated!
Try with port 587. Here is how the SMTP should be configured.
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.EnableSsl = True
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.UseDefaultCredentials = False
smtp.Credentials = New NetworkCredential("info#xxx.org", "mypwd")
And if it still doesn't work, fire up Command Prompt and do this.
Open the Start menu, and select Run.
Enter command in the Open: field, and click OK.
Enter 'telnet smtp.gmail.com 465,' and hit Enter, or if you're using Outlook 2007, enter 'telnet smtp.gmail.com 587' instead. (Does the information in the prompt window clear? If not, please note the message that appears.)
Close the prompt window.
Google help center link: http://support.google.com/mail/bin/answer.py?hl=en&answer=78775
Related
I recently migrated my ASP.Net website from a traditional windows 2003 shared server to Azure as a Web App. My VBScript forms which send e-mails to me have stopped working since the migration. I have tried a few different approaches to get my VBScript email code to work but have had no luck so far. Part of the problem is that I can't see what the error is.
The first part of my question is: How do I make the ASP.Net errors on my VBScript ASP page visible? I have set debug='true' in my web.config and I tried to set it on my ASP page (see below) but this hasn't worked. Currently I just get an 'Internal error 500' page after attempting to send the email with no indication of what went wrong.
Here is the code that sends the e-mail and appears to be the source of the problem. Can do I change this to work under Azure without rewriting my entire page in C#?
<%# Language=VBScript Debug='true' %> 'Debug=true doesn't work
Set Mailer = Server.CreateObject("Persits.MailSender")
Mailer.Host = "mail.mydomain.com" ' Specify a valid SMTP server
Mailer.From = Request.Form("AgentEmail") ' Specify sender's address
Mailer.FromName = Request.Form("AgentsName") ' Specify sender's name
Mailer.Port = 587
Mailer.isHTML = True
Mailer.AddAddress "person1#email.com"
Mailer.AddAddress "person2#email.net"
Mailer.AddAddress "person3#email.com"
Mailer.AddAddress Request.Form("AgentEmail")
Mailer.Body = "stuff in my email"
Mailer.Username = "me#emailcom"
Mailer.Password = "123456"
On Error Resume Next
Mailer.Send
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
Else
Response.Write "Success"
End If
This code did work on my old Windows server. I've left out all of the HTML since that part appears to work just fine.
Assuming you're using Azure Websites (and not an Azure VM), you can use Classic ASP provided you jump through some hoops: https://khailiangtech.wordpress.com/2011/06/03/windows-azure-how-to-enable-classic-asp-support/
Windows Azure seems to support CDO (the built-in COM SMTP service) whereas your code is using Persits.MailSender - it might be possible to install the Persits.MailSender component via the <ServiceDefinition> XML - but I don't recommend this because of the 32/64-bit problem.
I suggest changing your script to use CDO instead, here's a reference: http://theholmesoffice.com/using-sendgrid-with-classic-asp-to-send-emails/ (the page is for using SendGrid's SMTP server, but you can use any SMTP server (just don't use port 25).
You're trying to instantiate an object from a DLL that is not installed: Server.CreateObject("Persits.MailSender")
You can't install any external COM object when using Web Apps. One option is to use a Virtual Machine and install your COM DLL.
For future reference, I ended up solving my problem by converting my code to C# and using to smtpClient. This is the general idea here:
SmtpClient smtpClient = new SmtpClient("mail.domain.com", 587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(From, "password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Port = 587;
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(From, "Me");
smtpClient.Host = "mail.domain.com";
message.From = fromAddress;
message.To.Add(To);
message.Subject = Subject;
message.IsBodyHtml = true;
message.Body = Body;
smtpClient.Send(message);
Label_Results.Text = "Email successfully sent.";
}
catch (Exception ex)
{
ErrorLabel.Text = "<p>Send Email Failed:<p>" + ex.Message;
}
I am producing a website for a friends company and they would like customers to be able to contact them using a form on the website that will email the query to their work email address.
All the examples I have been able to find use GMail's SMTP server. I have managed to get this to work using the code below but e-mails always appear in the inbox as from the GMail account, regardless of what I set mm.From to be. I understand that this is the downside to using GMail's SMTP server.
Dim mm As MailMessage = New MailMessage()
mm.From = New MailAddress("customer#test.com")
mm.Subject = "Test Email"
mm.Body = "<p>This is a test email</p>"
mm.IsBodyHtml = True
mm.To.Add(New MailAddress("info#myCompany.com"))
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
Dim NetworkCred As NetworkCredential = New System.Net.NetworkCredential()
NetworkCred.UserName = "mycompany#gmail.com"
NetworkCred.Password = "myPassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
Try
smtp.Send(mm)
Catch ex As Exception
Response.Write(ex)
End Try
I would like the senders e-mail address to appear in the from field so users can just click reply when a message comes in.
The business e-mail account they have is provided by GoDaddy and I have tried entering the SMTP and account details in the code but I get the following error:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Any help would be greatly appreciated.
Thanks
You can use any SMTP service that you have access to. So if GMail's doesn't do what you need, try another one. (The settings for that other one may be different, check with the service host for details.)
However, one thing you can definitely do in your code is set a ReplyTo address. From is only one header in the message, there are others that can be used. A ReplyTo header tells the email client that replies should be sent to a given email address.
mm.ReplyTo = New MailAddress("customer#test.com")
Not sure if this question has been asked elsewhere...
For a website project that I'm working on, I created an ASPX web form that will send an email containing the contents of the form on button click. I tried it and it worked when I'm using the Yahoo SMTP server and testing using my personal Yahoo email address (+ specifying the username and password).
However, it wouldn't work when I'm using the SMTP server for mail messages for the website (after I've created a new admin email account in the website).
The website is up and running and I'm able to send an email to the website's admin email account (through Yahoo) but just not when sending through the ASPX web form.
Here is the code for using the Yahoo SMTP server and it works fine:
SmtpServer.Credentials = New Net.NetworkCredential("username#yahoo.com", "password")
SmtpServer.Port = "25"
SmtpServer.Host = "smtp.mail.yahoo.com"
mail.From = New MailAddress("username#yahoo.com")
mail.To.Add("username#yahoo.com")
mail.Subject = "RE: Message Subject"
mail.Body = "Message goes here."
SmtpServer.Send(mail)
Now, here is the code for using my website's SMTP server which doesn't work:
SmtpServer.Port = "25"
SmtpServer.Host = "127.0.0.1"
mail.From = New MailAddress("admin#awesomewebsite.org.au")
mail.To.Add("admin#awesomewebsite.org.au")
mail.Subject = "RE: Message Subject"
mail.Body = "Message goes here."
SmtpServer.Send(mail)
These are the correct port and host numbers given by the web hosting company that hosts the website. They also said that username and password are not needed. I also tried appending this to the beginning of the code but it still wouldn't work:
SmtpServer.Credentials = New Net.NetworkCredential()
or even
SmtpServer.Credentials = New Net.NetworkCredential("", "")
I really don't know what to do. Please help this newbie out. Any response is appreciated.
By the way, the error message that I get when I test this out appears in a message box: "Failure sending mail."
You need to create an email account in your web site and use those credentials to send the mail just as you did with yahoo (This can be done in your admin portal of the website but some hosting providers will charge you separately for the email service). Further more the correct smtp server is also should be given, that depends on your hosting provider. You can get that information from your hosting provider. 127.0.0.1 will not work here anyway.
Don't import 'System.Net.Mail'.
Completed code is shown below:
Dim SmtpServer As New Net.Mail.SmtpClient
Dim mail As New Net.Mail.MailMessage
SmtpServer.Host = "198.154.99.8"
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New System.Net.NetworkCredential("admin#awesomewebsite.org.au", "password")
mail.From = New Net.Mail.MailAddress("admin#awesomewebsite.org.au")
mail.To.Add("admin#awesomewebsite.org.au")
mail.Subject = "RE: Message Subject"
mail.Body = "Message goes here."
SmtpServer.Send(mail)
//Create Mail Message Object with content that you want to send with mail.
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("dotnetguts#gmail.com", "myfriend#yahoo.com",
"This is the mail subject", "Just wanted to say Hello");
MyMailMessage.IsBodyHtml = false;
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("dotnetguts#gmail.com", "myPassword");
//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
Thats my code & it throws error :
No connection could be made because the target machine actively refused it 72.14.213.109:587
Code Reference : here
Please tell me how can i sought it out ??
Check both of the following points
1- Check that this port 587 is open on your machine
2- Check if your antivirus is blocking the connection to your port
Regards.
If your have any antivirus software running, check the access protection, unblock "prevent mass mailing worms from send mail"
Did you actually change the username and password?
Does anyone know what the smtp mail configuration settings are that is needed in the web.config file to send outgoing mail through a form in ASP? Thanks.
Check out this link: Yahoo POP3 and SMTP Settings
My guess is the following should work in your code (not exactly sure about credentials as I do not have an account to test with):
MailMessage mail = new MailMessage();
mail.From = new MailAddress("fromname#somewhere.com");
mail.To.Add("toname#somewhereelse.com");
mail.Subject = "The Subject";
mail.Body = "Body text here";
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com");
smtp.Port = 465; // this could be 587, not sure
smtp.Credentials = new NetworkCredential("YourYahooId", "YourYahooPassword");
smtp.EnableSsl = true; // SSL is required I think
smtp.Send(mail);
The key is to make sure you are using SSL and send authentication credentials. I don't think you will be able to do SSL with just the web.config mail settings. Please see this question for more information.
See the How to utilize Google gmail server in your.NET Web & Windows Applications article. That code work for me. If it doesn't work for you, send mail to me(pandiansaamy#gmail.com)
SMTP_SERVER = "smtp.mail.yahoo.com"
SMTP_PORT = 587
SMTP_USERNAME = "username" // username#yahoo.com
SMTP_PASSWORD = "password"