Sending mail using SMTP
-
Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth
-
Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth
Elizabeth Rani wrote:
this code works fine
Really? Have ever looked at
lblmsg
? Nowhere did you set theHost
,Port
,EnableSsl
, andCredentials
properties of theSmtpClient
. It must fail because of that. Next, some mail providers check that theFrom
property of theMailMessage
is the address of the user identified by theUserName
of theCredentials
- in case of doubt, they'll refuse to send the mail. -
Elizabeth Rani wrote:
this code works fine
Really? Have ever looked at
lblmsg
? Nowhere did you set theHost
,Port
,EnableSsl
, andCredentials
properties of theSmtpClient
. It must fail because of that. Next, some mail providers check that theFrom
property of theMailMessage
is the address of the user identified by theUserName
of theCredentials
- in case of doubt, they'll refuse to send the mail.Hi, Can you help me some sort of code please. Thanks in advance
-
Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth
Dim strMsg As String strMsg = txtMessage.Text If strMsg.Length >= 140 Then strMsg = strMsg.Substring(1, 140) End If mTo = Trim(txtToNumber.Text) & _ Trim(cboCarrier.SelectedItem.ToString()) mFrom = Trim(txtFrom.Text) mSubject = Trim(txtSubject.Text) mMsg = Trim(txtMessage.Text) mMailServer = ConfigurationManager.AppSettings.Get("MyMailServer") mPort = ConfigurationManager.AppSettings.Get("MyMailServerPort") Try Dim message As New MailMessage(mFrom, mTo, mSubject, mmsg) Dim mySmtpClient As New SmtpClient(mMailServer, mPort) mySmtpClient.UseDefaultCredentials = True mySmtpClient.Send(message) MessageBox("The mail message has been sent to " & _ message.To.ToString()) Catch ex As FormatException MessageBox("Format Exception: " & ex.Message) Catch ex As SmtpException MessageBox("SMTP Exception: " & ex.Message) Catch ex As Exception MessageBox("General Exception: " & ex.Message) End Try End Sub