I was having the same issues, however your solution solved it for me (Using Visual web developer 2008 ,C#) , my question is this, i need a simple instruction, using regular HTML, to send email, using just a button and text boxes?
something like below code
System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(myname@gmial.com, "mygmailPass");
For reasons I explained here - http://forums.asp.net/p/1347995/2744618.aspx#2744618 - I don't want to pre-set the
mailSettings section of web.config. In order to use the Password Recovery control, can I programmatically populate
mailSettings on-the-fly?
Thank you for the guidance on creating the connection to send e-mails. I had the similar gmail problem you helped solve.
However, I wanted to get rid of the hard-coded strings and leverage the mail connection established through IIS as captured in web.config.
The following code builds off your example to get rid of the hard-codes. I'm not very experienced at ASP.net so perhaps there is a more efficient way to perform these calls.
Thanks for your help.
Kieran Hooks
RecoverPassword.aspx.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Configuration;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class RecoverPassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
MembershipUser u = Membership.GetUser(PasswordRecovery1.UserName);
Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("~");
MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;
System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient(mailSettings.Smtp.Network.Host, mailSettings.Smtp.Network.Port);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(mailSettings.Smtp.Network.UserName, mailSettings.Smtp.Network.Password);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = nc;
s.Send(e.Message.From.Address, u.Email, "Password Change", e.Message.Body);
}
protected void PasswordRecovery1_SendMailError(object sender, SendMailErrorEventArgs e)
{
e.Handled = true;
}
}
I am using asp.net with sql server. for mailing I use database mailing, actually i am new in this field. I configure database mail and test mail send succesfully. but I dont know how to confugure it locally, The live site working well and can able to send
mail, but the client need aome updation and so I need to configure it locally, but I cant send mail yet. Actually I dont know how to send mail through this way. While I am sending using smtp.gmail.com with 25 port I get the error
530 5.7.0 Must issue a STARTTLS command first. bq1sm3641302vbb.22
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: aspNetEmail.SmtpProtocolException: 530 5.7.0 Must issue a STARTTLS command first. bq1sm3641302vbb.22
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Source Error:
Line 229: Line 230: Catch ex As Exception Line 231: Throw Line 232: Finally Line 233: If (Not msg Is Nothing) Then
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
and while I use our own smtp server I got the error
Server Error in '/MarketBlox' Application.
551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: aspNetEmail.SmtpProtocolException: 551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Source Error:
Line 229: Line 230: Catch ex As Exception Line 231: Throw Line 232: Finally Line 233: If (Not msg Is Nothing) Then
darkwarriorj...
Member
20 Points
25 Posts
Re: 5.7.0 Must issue a STARTTLS command first.
Aug 27, 2008 07:51 PM|LINK
Satalaj,
I was having the same issues, however your solution solved it for me (Using Visual web developer 2008 ,C#) , my question is this, i need a simple instruction, using regular HTML, to send email, using just a button and text boxes?
satalaj
Star
10505 Points
2031 Posts
MVP
Re: 5.7.0 Must issue a STARTTLS command first.
Aug 29, 2008 03:06 PM|LINK
something like below code
System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(myname@gmial.com, "mygmailPass");
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = nc;
s.Send("myname@gmail.com", email, "subject", "email body" );
Satalaj
darkwarriorj...
Member
20 Points
25 Posts
Re: 5.7.0 Must issue a STARTTLS command first.
Aug 29, 2008 10:05 PM|LINK
Thanks Satalaj, That worked for me Good stuff!
All the best
Darkwarriorjam
rmdw
Participant
825 Points
1228 Posts
Re: 5.7.0 Must issue a STARTTLS command first.
Nov 14, 2008 04:21 AM|LINK
Satalaj,
For reasons I explained here - http://forums.asp.net/p/1347995/2744618.aspx#2744618 - I don't want to pre-set the mailSettings section of web.config. In order to use the Password Recovery control, can I programmatically populate mailSettings on-the-fly?
Robert
Vancouver, BC
Technical Blog
Pocket Pollster
satalaj
Star
10505 Points
2031 Posts
MVP
Re: 5.7.0 Must issue a STARTTLS command first.
Nov 14, 2008 11:42 AM|LINK
Hi Robert,
There is no need to preset the Mail settings. if you read all posts from start you will get rid of it.
Satalaj
Kieran Hooks
Member
2 Points
1 Post
Re: 5.7.0 Must issue a STARTTLS command first.
Dec 11, 2009 04:17 PM|LINK
Satalaj,
Thank you for the guidance on creating the connection to send e-mails. I had the similar gmail problem you helped solve.
However, I wanted to get rid of the hard-coded strings and leverage the mail connection established through IIS as captured in web.config.
The following code builds off your example to get rid of the hard-codes. I'm not very experienced at ASP.net so perhaps there is a more efficient way to perform these calls.
Thanks for your help.
Kieran Hooks
RecoverPassword.aspx.cs
using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Configuration; using System.Web; using System.Web.Configuration; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; public partial class RecoverPassword : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e) { MembershipUser u = Membership.GetUser(PasswordRecovery1.UserName); Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("~"); MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup; System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient(mailSettings.Smtp.Network.Host, mailSettings.Smtp.Network.Port); System.Net.NetworkCredential nc = new System.Net.NetworkCredential(mailSettings.Smtp.Network.UserName, mailSettings.Smtp.Network.Password); s.EnableSsl = true; s.UseDefaultCredentials = false; s.Credentials = nc; s.Send(e.Message.From.Address, u.Email, "Password Change", e.Message.Body); } protected void PasswordRecovery1_SendMailError(object sender, SendMailErrorEventArgs e) { e.Handled = true; } }satalaj
Star
10505 Points
2031 Posts
MVP
Re: 5.7.0 Must issue a STARTTLS command first.
Dec 14, 2009 05:24 AM|LINK
Hi,
You can get your email addresses,SMTP server adress, port numbers etc.
from Database and replace appropriate hard coded strings.
Satalaj
Mirosta
Member
2 Points
1 Post
Re: 5.7.0 Must issue a STARTTLS command first.
Mar 01, 2010 07:41 PM|LINK
Some changes to the SendingEmail Event:
System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("myname", "mypass"); s.EnableSsl = true; s.UseDefaultCredentials = false; s.Credentials = nc; s.Send(e.Message); e.Cancel = trues.Send(e.Message) is quicker than retyping all the e.message properties, and e.Cancel = true stops the original email from being sent.
fusion1
Member
6 Points
10 Posts
Re: 5.7.0 Must issue a STARTTLS command first.
Jun 13, 2011 07:02 AM|LINK
hi
I am using asp.net with sql server. for mailing I use database mailing, actually i am new in this field. I configure database mail and test mail send succesfully. but I dont know how to confugure it locally, The live site working well and can able to send mail, but the client need aome updation and so I need to configure it locally, but I cant send mail yet. Actually I dont know how to send mail through this way. While I am sending using smtp.gmail.com with 25 port I get the error
530 5.7.0 Must issue a STARTTLS command first. bq1sm3641302vbb.22
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: aspNetEmail.SmtpProtocolException: 530 5.7.0 Must issue a STARTTLS command first. bq1sm3641302vbb.22
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Source Error:
Source File: F:\Prajeesh\MarketBlox\EmailBloxJP\EmailVerification.aspx.vb Line: 231
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
and while I use our own smtp server I got the error
Server Error in '/MarketBlox' Application.
551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: aspNetEmail.SmtpProtocolException: 551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.
(Missing Reply Code'250') [Additional Help:Reply From FROM ]
Source Error:
Source File: F:\Prajeesh\MarketBlox\EmailBloxJP\EmailVerification.aspx.vb Line: 231
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
I cant identyfy the reason for Why I cant send mail using locally cofigured site and how it work in live site?
Any one can help me please because I am new in this Please.....
Thanks.
Praj