本文整理汇总了C#中SendGrid.Web.DeliverAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Web.DeliverAsync方法的具体用法?C# Web.DeliverAsync怎么用?C# Web.DeliverAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SendGrid.Web
的用法示例。
在下文中一共展示了Web.DeliverAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
// POST: api/Email
public IHttpActionResult Post (Email emailMessage)
{
var mailMessage = new SendGridMessage();
mailMessage.AddTo("[email protected]");
try {
mailMessage.From = new MailAddress(emailMessage.EmailAddress);
} catch {
ModelState.AddModelError("Email", "Invalid Email Address");
}
mailMessage.Subject = "Forest Film Contact";
mailMessage.Text = emailMessage.Message +"\n\nName: " + emailMessage.FirstName + " " + emailMessage.LastName + "\nEmail: " + emailMessage.EmailAddress + "\nPhone: " + emailMessage.Phone;
var transportWeb = new Web("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");
try
{
if (!ModelState.IsValid)
{
return BadRequest(this.ModelState);
}
transportWeb.DeliverAsync(mailMessage).Wait();
return Ok();
}
catch {
ModelState.AddModelError("Error", "There was an error sending your message, please try again soon");
return BadRequest(this.ModelState);
}
}
示例2: SendEmailAsync
public async Task SendEmailAsync( string destination, string subject, string body )
{
var myMessage = new SendGridMessage();
myMessage.AddTo(destination);
myMessage.From = new System.Net.Mail.MailAddress(
ConfigurationManager.AppSettings["emailService:FromAddress"],
ConfigurationManager.AppSettings["emailService:FromName"]);
myMessage.Subject = subject;
myMessage.Text = body;
myMessage.Html = body;
var credentials = new NetworkCredential(ConfigurationManager.AppSettings["emailService:Account"],
ConfigurationManager.AppSettings["emailService:Password"]);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
//Trace.TraceError("Failed to create Web transport.");
await Task.FromResult(0);
}
}
示例3: SimplePlaintextEmail
/// <summary>
/// Send a simple Plain Text email
/// </summary>
public void SimplePlaintextEmail()
{
//create a new message object
var message = new SendGridMessage();
//set the message recipients
foreach (var recipient in _to)
{
message.AddTo(recipient);
}
//set the sender
message.From = new MailAddress(_from);
//set the message body
message.Text = "Hello World Plain Text";
//set the message subject
message.Subject = "Hello World Plain Text Test";
//create an instance of the Web transport mechanism
var transportInstance = new Web(new NetworkCredential(_username, _password));
//send the mail
transportInstance.DeliverAsync(message);
}
示例4: Submit_Click
protected void Submit_Click(object sender, EventArgs e)
{
String contact = "";
if (!string.IsNullOrWhiteSpace(mobile.Text))
contact = "Contact number: " + mobile.Text;
// SendGrid credentials
var credentials = new NetworkCredential(
ConfigurationManager.AppSettings["SendGridUserId"],
ConfigurationManager.AppSettings["SendGridPassword"]);
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo("[email protected]");
myMessage.From = new MailAddress(email.Text, name.Text);
myMessage.Subject = "Feedback: " + subject.Text;
myMessage.Html = contact + "<p>" + message.Text + "</p>";
// Create an Web transport for sending email, using credential
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.DeliverAsync(myMessage);
email.Text = "";
name.Text = "";
mobile.Text = "";
subject.Text = "";
message.Text = "";
}
示例5: SendMailNotification
public async void SendMailNotification(string sharePointAppUrl, string name, string useremail = null)
{
string description = $"Sharepoint site '{name}' created.";
var urlValue = "<a href=" + name + ">" + sharePointAppUrl + "</a>";
object[] parameters = { description , urlValue };
var msgBody = GetMailMessage(parameters);
var mailMessage = new SendGridMessage();
var mailFrom = WebConfigurationManager.AppSettings["MailFrom"];
var maintenanceEmailAddress = WebConfigurationManager.AppSettings["MaintenanceEmailAddress"];
var mailUserName = WebConfigurationManager.AppSettings["MailUserID"];
var mailPassword = WebConfigurationManager.AppSettings["MailPassword"];
mailMessage.From = new MailAddress(mailFrom);
var recipients = new List<string> {maintenanceEmailAddress};
if (useremail != null)
{
recipients.Add(useremail);
}
recipients.Add(mailFrom);
mailMessage.AddTo(recipients);
mailMessage.Subject = description;
mailMessage.Html = msgBody;
var credentials = new NetworkCredential(mailUserName, mailPassword);
var transportWeb = new Web(credentials);
await transportWeb.DeliverAsync(mailMessage);
}
示例6: SendMailAsync
public async Task<bool> SendMailAsync(MailMessage mm, bool suppressExceptions=true)
{
try
{
string userName = _configurationService.SendGridUsername;
string password = _configurationService.SendGridPassword;
var message = new SendGridMessage();
message.From = new MailAddress(mm.From);
message.AddTo(mm.To);
message.Subject = mm.Subject;
message.Text = mm.Body;
var credentials = new NetworkCredential(userName, password);
var transportWeb = new Web(credentials);
await transportWeb.DeliverAsync(message).ConfigureAwait(false);
return true;
}
catch (Exception ex)
{
Trace.TraceError(ex.ToString());
if (!suppressExceptions)
throw;
}
return false;
}
示例7: Send
public void Send()
{
var myMessage = new SendGridMessage();
//myMessage.From = new MailAddress("[email protected]");
//myMessage.From = new MailAddress("[email protected]");
myMessage.From = new MailAddress("[email protected]");
myMessage.AddTo(this.ToAddress);
myMessage.Subject = "PiSpy Notification";
myMessage.Text = this.Body;
//John
//var credentials = new NetworkCredential(
// "[email protected]",
// "69g8nntNJB1zm59");
//Jeff
//var credentials = new NetworkCredential(
// "[email protected]",
// "Sn6Rz2gVDeZlbG1");
//Klayton
var credentials = new NetworkCredential(
"[email protected]",
"8IL1tfpWYGquj6a");
var transportWeb = new Web(credentials);
var results = transportWeb.DeliverAsync(myMessage);
}
示例8: ConfigSendGridasync
private async Task ConfigSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress("[email protected]", "Система за гласуване.");
myMessage.Subject = message.Subject;
myMessage.Html = message.Body;
var transportWeb = new Web("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");
try
{
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
await Task.FromResult(0);
}
}
catch (Exception ex)
{
throw ex;
}
}
示例9: configSendGridasync
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.AddBcc("[email protected]");
myMessage.From = new MailAddress("[email protected]", "Account | Calgary School Buses");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(ConfigurationManager.AppSettings["SendGridUsername"], ConfigurationManager.AppSettings["SendGridPassword"]);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
try
{
await transportWeb.DeliverAsync(myMessage);
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
示例10: Post
// POST: api/RequestData
public HttpResponseMessage Post([FromBody]RequestData value)
{
try
{
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo("[email protected]");
myMessage.From = new MailAddress("[email protected]");
myMessage.Subject = string.Format("Message from DRB Technology");
myMessage.Text = string.Format("From: {0} {1} \n Message: {2}", value.email, value.yourName, value.yourRequest);
// Create credentials, specifying your user name and password.
//TODO: Set credentials
var credentials = new NetworkCredential("", "");
// Create an Web transport for sending email, using credentials...
var transportWeb = new Web(credentials);
// ...OR create a Web transport, using API Key (preferred)
//var transportWeb = new Web("This string is an API key");
// Send the email.
transportWeb.DeliverAsync(myMessage);
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException);
}
return Request.CreateResponse(HttpStatusCode.OK, "Thank you for your request. We aim to respond within 24 hours.");
}
示例11: FeedbackEmailAsync
private async Task FeedbackEmailAsync(FeedbackViewModel message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo("[email protected]");
myMessage.From = new System.Net.Mail.MailAddress(message.Email, message.Name);
myMessage.Subject = message.Subject;
myMessage.Html = message.Message;
var transportWeb = new Web("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");
try
{
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
await Task.FromResult(0);
}
}
catch (Exception ex)
{
throw ex;
}
}
示例12: configSendGridasync
// Use NuGet to install SendGrid (Basic C# client lib)
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress(
"[email protected]", "LaFactureria");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(
ConfigurationManager.AppSettings["mailAccount"],
ConfigurationManager.AppSettings["mailPassword"]
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
Trace.TraceError("Fallo al crear el transporte Web y no se fue posible enviar el correo.");
await Task.FromResult(0);
}
}
示例13: EmailReceipt
public void EmailReceipt(byte[] file, string fileName, OrderViewModel order)
{
// Set our SendGrid API User and Key values for authenticating our transport.
var sendGridApiKey = "";
var sendGridApiUser = "";
// Create the email object first, and then add the properties.
var myMessage = new SendGridMessage();
// Add the message properties.
myMessage.From = new MailAddress("[email protected]");
// Add customer's email addresses to the To field.
myMessage.AddTo(order.Email);
myMessage.Subject = "Contoso Sports League order received";
// Add the HTML and Text bodies.
myMessage.Html = "";
myMessage.Text = "";
// Add our generated PDF receipt as an attachment.
using (var stream = new MemoryStream(file))
{
myMessage.AddAttachment(stream, fileName);
}
var credentials = new NetworkCredential(sendGridApiUser, sendGridApiKey);
// Create a Web transport using our SendGrid API user and key.
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.DeliverAsync(myMessage);
}
示例14: Process
public async Task<ProviderProcessResult> Process(Message message)
{
try
{
var msg = new SendGridMessage();
msg.AddTo(message.To);
msg.From = new MailAddress(message.Application.EmailFromAddress, message.Application.EmailFromFullName);
msg.Subject = message.Subject;
msg.Html = message.Content;
var transportWeb = new Web(ConfigurationManager.AppSettings["SendGridSecretKey"]);
await transportWeb.DeliverAsync(msg);
return new ProviderProcessResult { IsSuccess = true };
}
catch (Exceptions.InvalidApiRequestException ex)
{
return new ProviderProcessResult { IsSuccess = false, ErrorMessage = String.Join(",", ex.Errors), ErrorDetails = ex.ToString() };
}
catch (Exception ex)
{
return new ProviderProcessResult { IsSuccess = false, ErrorMessage = ex.Message, ErrorDetails = ex.ToString() };
}
}
示例15: configSendGridasync
// Use NuGet to install SendGrid (Basic C# client lib)
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress("[email protected]", "Francisco Paz");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
// Create network credentials to access your SendGrid account
var username = "";
var pswd = "";
var credentials = new NetworkCredential(username, pswd);
//var credentials = new NetworkCredential(ConfigurationManager.AppSettings["emailService:Account"],
// ConfigurationManager.AppSettings["emailService:Password"]);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
//Trace.TraceError("Failed to create Web transport.");
await Task.FromResult(0);
}
}