This my working method to send a email
Sub emailConfirm()
Dim email As String = txtMail.Text
Dim name As String = txtPrenom.Text + txtNom.Text
Dim mail As MailMessage = New MailMessage()
'mail.To.Add("francois.smtp#gmail.com")
mail.To.Add(email)
mail.From = New MailAddress("sumerman#gmail.com.com")
mail.Subject = "Email using Gmail"
Dim Body As String = "Hi " + name + ", this mail is to confirm your registration" + "Click on the link to confirm please" + " Link(check note) "
mail.Body = Body
mail.IsBodyHtml = True
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.Credentials = New System.Net.NetworkCredential("sumerman#gmail.com", "12345")
smtp.EnableSsl = True
smtp.Send(mail)
End Sub
note:I want to send Link contains a unique identifier and verify the unique identifier in the login.aspx
I don't know when to do this...
I found nothing interesting on the net ...
This is in Vb.net
I will add security later
Thank's for your helping!
Well, first off don't put the username and password in the email itself. That's a bit sloppy.
Second, most sites now do the following:
User creates account
Email sent to user. Link in email contains a unique identifier, not the username and password.
User clicks on link. At this point the page tests to see if the unique id is valid. If so, it tells them Thank You for confirming your account. It then displays the login form.
User enters their login credentials.
Note that the email did NOT send the actual username/pw info.
Related
I have a ASP.NET web form for sending emails using SMTP. The hosting provider is 1and1. It worked for year. It stopped working several weeks ago. I receive the following error:
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required"
1and1 support is unable to explain the reason for the change. I would appreciate your help (see the VB.NET code below).
I tried to change the port to 465 and 587, as well, I tried to change "EnableSsl" flag to true state - nothing worked.
I wrote another code that works, but it allows to send an email with my email address in the "from" field (see the code below). But I would like to send an email with visitors' address in the "from" field.
' code that worked once
Dim mailMessage As New MailMessage()
Dim MailAddress As String
Try
'creating an instance of the MailMessage class
mailMessage.From = New MailAddress(txtEmail.Text)
'senders email address
mailMessage.To.Add("me#mysite.net")
'recipient's email address
mailMessage.Subject = "Form Submission: " & txtSubject.Text
'subject of the email message
mailMessage.IsBodyHtml = False
'message text format. Can be text or html
mailMessage.Body = txtName.Text & vbCr & txtEmail.Text
'message body
mailMessage.Priority = MailPriority.Normal
'email priority. Can be low, normal or high
Dim smtp As New SmtpClient("smtp.ionos.com")
smtp.Port = 25
smtp.EnableSsl = False
smtp.Send(mailMessage)
'using the static method "Send" of the SmtpMail class to send the mail
Response.Write("Mail sent")
Catch ex As Exception
lblError.Text = "Form processing error occurred." & vbCr & "Please send your request to: me#mysite.net"
End Try
' code that is working today, but my email address must be in the "from" field
Dim mailMessage As New MailMessage()
Dim MailAddress As String
Try
'creating an instance of the MailMessage class
mailMessage = New MailMessage()
mailMessage.From = New MailAddress("me#mysite.net")
'senders email address
mailMessage.To.Add("me#mysite.net")
'recipient's email address
mailMessage.Subject = "Form Submission: " & txtSubject.Text
'subject of the email message
mailMessage.IsBodyHtml = False
'message text format. Can be text or html
mailMessage.Body = txtName.Text & vbCr & txtEmail.Text
'message body
mailMessage.Priority = MailPriority.Normal
'email priority. Can be low, normal or high
Dim smtp As New SmtpClient'("smtp.ionos.com")
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("me#mysite.net", "MyPassword")
smtp.Host = "smtp.ionos.com"
smtp.Port = 587
smtp.EnableSsl = True
smtp.Send(mailMessage)
'using the static method "Send" of the SmtpMail class to send the mail
Response.Write("Mail sent")
Catch ex As Exception
lblError.Text = "Form processing error occurred." & vbCr & "Please send your request to: me#mysite.net"
End Try
I am trying to send an email from an ASP page using gmail, but when I try to send it, i just get "Error sending mail", with no description other than that.
SMTP is enabled on the gmail box I'm using and also working from mobile devices.
If anyone could give me a hand with this, I'll appreciate it.
Thanks.-
Friend Shared Sub Send_Mail(Destinatario As String)
Dim Message As New MailMessage()
Dim SmtpC = New SmtpClient("smtp.gmail.com")
Message.From = New MailAddress("xxxx#gmail.com")
Message.To.Add(Destinatario)
Message.Subject = "Some Subject"
Message.Body = "Message body"
SmtpC.Port = 465
SmtpC.Credentials = New System.Net.NetworkCredential("xxxx#gmail.com", "somepassword")
SmtpC.EnableSsl = True
Try
SmtpC.Send(Message)
Catch ex As Exception
End Try
End Sub
im facing error when sending email. here is the error
what is the actual error for this exception because i newbie in in this, by the way here is my code line:
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("test#gmail.com", "passwordexample")
SmtpServer.EnableSsl = True
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("test#gmail.com")
mail.To.Add("examplemail#gmail.com")
mail.Subject = "Change Request Submitted"
mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & Environment.NewLine & Environment.NewLine & "One Notification have been submitted," & Environment.NewLine & "Please check the change request on the intranet application"
//ad this line the error SmtpServer.Send(mail)
SmtpServer.EnableSsl = True
MsgBox("Notification emailed successfully")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Please see this answer...
Sending Email from Visual Basic
If you still can't send the email....
Have you enabled POP or IMAP in Gmail?
Sign in to the Gmail web interface.Open the 'Forwarding and POP/IMAP' tab on your 'Settings' page, and configure IMAP or POP. After enabling this in Gmail, make sure you click 'Save Changes' so Gmail can communicate with your mail client.
If you have 2 step verification..
Get an Application-Specific Password
Google will automatically generate a password that you will need only once, when you set up Google Mail on your mobile device or email software. You can easily generate a password for each device or email software you want to use.
Step 1:
At the bottom of the 2-step verification screen, next to Application-specific passwords, click Manage application-specific passwords. The Authorized Access to your Google Account screen will open.
Step 2:
On the Authorized Access to your Google Account screen, in the Name field, type in a name to help you remember what application you are using to access your account and click Generate password. You will then see a password which you will use to configure your mobile device or email software. Keep this screen open until you are ready to enter the password (see part 4, below). The password creation with the device name will show at the bottom. When you are done using the password, click Done.
Step 3:
To set up a password for another device or email software, simply type in the name of it in the Name field and click Generate password. You will receive another password.
See more here...
http://www.oit.umass.edu/support/google-apps/configure-google-mail-email-software-mobile-devices
Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential("EMAIL FROM#gmail.com", "YOUR PASSWORD")
SmtpServer.Port = 25
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
Dim omail As New MailMessage()
omail.From = New MailAddress("FROM EMAIL #gmail.com", "Message", System.Text.Encoding.UTF8)
omail.Subject = "test subject"
omail.To.Add("test#gmail.com")
SmtpServer.SendAsync(omail, Nothing)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
if that didn't work try
SmtpServer.Port = 587
I want to receive email to my email address through my asp.net application. Its like someone who send an inquiry through a form. I have used the following code for this and seems like its doing nothing. I remember that I did one of my websites and cant remember how I did it. Please find the code below.
Thanks,
eMessage.To = "info#boilernetworkservices.co.uk"
eMessage.From = txtEmail.Text
eMessage.Subject = "Web Submission"
eMessage.Body = "Web submission received from " & txtName.Text & ". Phone no: " & txtPhone.Text & "."
eMessage.Priority = MailPriority.High
SmtpMail.Send(eMessage)
How can I make this working?
Your sample code shows how to use SMTP to send emails, but you won't be able to retrieve emails from a remote server using this protocol.
The two most common protocols used to retrieve emails are POP3 and IMAP4, and unfortunately the .NET framework doesn't provide an implementation of them like it is done with SMTP.
One option for email retrieval is to use use the open source POP3 client OpenPop.NET, which is discussed in this SO question: retrieve email using c#?.
I set up a google account for my business like myCompanyName#gmail.com.
And I use that as a relay.
You have to set your google account to "Allow less secure apps".
Here is my code to let a potential client fill out a contact us from and send the info to me (Even works when I publish to Azure:)):
private void SendEmailToMyCompany(ContactInfo contactInfo)
{
string message = contactInfo.Message.Replace("\n", "<br />");
MailAddress from = new MailAddress(contactInfo.Email);
MailAddress to = new MailAddress("myhotmailaccount#hotmail.com");
MailMessage mailMessage = new MailMessage(from, to);
StringBuilder body = new StringBuilder();
body.AppendFormat($"<b>First Name:</b> {contactInfo.FirstName}");
body.Append("<br />");
body.AppendFormat($"<b>Last Name:</b> {contactInfo.LastName}");
body.Append("<br />");
body.AppendFormat($"<b>Phone:</b> {contactInfo.Phone}");
body.Append("<br />");
body.AppendFormat($"<b>Email:</b> {contactInfo.Email}");
body.Append("<br />");
body.AppendFormat($"<b>Message:</b><br /><br /> {message}");
mailMessage.Body = body.ToString();
mailMessage.Subject = "MyCompany Customer Contact";
mailMessage.IsBodyHtml = true;
string smtpHost = _config["EmailSettings:SmtpHost"];
string port = _config["EmailSettings:Port"];
string userName = _config["EmailSettings:UserName"];
string password = _config["EmailSettings:Password"];
SmtpClient client = new SmtpClient(smtpHost)
{
Port = int.Parse(port),
Credentials = new NetworkCredential(userName, password),
EnableSsl = true
};
client.Send(mailMessage);
}
And then here is my email settings from app.config:
"EmailSettings": {
"SmtpHost": "smtp.gmail.com",
"Port": 587,
"UserName": "myCompanyNameGmailAccount#gmail.com",
"Password": "**********"
}
Hi I am trying to send a picture attachment to some email via ASP.NET. The program works without any problem, but I cannot visualize the attached picture in some email programs, such as iPhone's email program for Yahoo email. I suspect I am not attaching correctly the picture.
It works ok on my desktop pc
When the email is loaded I cannot see the picture.
Dim mail As New MailMessage()
mail.From = New MailAddress("xxxxxxxx", "xxxxxxx")
mail.To.Add(DirectCast(RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email"), TextBox).Text)
mail.Subject = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
mail.Body = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Dim htmlBody As String = "<html><body><DIV style=""background-color:#5B37AE"">"
htmlBody += "<img height=""70px"" width=""150px"" src=cid:HDIImage /></DIV></body></html>"
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody, Nothing, "text/html")
Dim imageResource As New System.Net.Mail.LinkedResource(Server.MapPath("~/Images/Site/background_main2.png"))
imageResource.ContentId = "HDIImage"
htmlView.LinkedResources.Add(imageResource)
mail.AlternateViews.Add(htmlView)
Dim j As New SmtpClient
j.Host = "hostingxxxxx"
j.EnableSsl = False
j.Credentials = New System.Net.NetworkCredential("usernam", "passw")
j.Send(mail)
Thanks
It was not necessary to attach via linkedresoruce, adding src="http://wwww.mysite.com/myimage.jpg" works ok in every (modern) browser