Jump to content
Gabriel87

C# send mail via smtp

Recommended Posts

Posted

/// <author>sunjester / fusecurity.com</author>
/// <summary>
/// sends email from an smtp server
/// </summary>
/// <param name="toEmail">who to send it to</param>
/// <param name="fromEmail">who it's from</param>
/// <param name="smtpAddr">the smtp server</param>
/// <param name="smtpPort">the smtp port</param>
/// <param name="smtpUser">the username for the smtp server</param>
/// <param name="smtpPass">the password for the smtp server</param>
/// <param name="smtpSubject">the subject of the email</param>
/// <param name="ssl">enable ssl?</param>
/// <param name="content">message to send, body of the email</param>
/// <returns>string</returns>
public string sendMessage(string toEmail, string fromEmail, string smtpAddr, int smtpPort, string smtpUser, string smtpPass, string smtpSubject, bool ssl, string content)
{
try
{
MailMessage msg = new MailMessage();
msg.To.Add(toEmail);
msg.From = new MailAddress(fromEmail);
msg.Subject = smtpSubject;
msg.Body = content;
SmtpClient client = new SmtpClient(smtpAddr);
client.Port = smtpPort;
client.EnableSsl = ssl;
client.Credentials = new NetworkCredential(smtpUser, smtpPass);
client.Send(msg);
return "success";
}
catch (Exception ex)
{
return "error: "+ex.Message;
}
}

Sursa : http://h4ck3r.in/board/showthread.php?tid=1803

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...